I have a question regarding getting numbers out of the file..
SO basically my file has numbers and text in it, therefore i am going thorugh the file character by character and i am using
a series of if-statements to see whteher chcaracter is a number, comma, carriage return or just a character.
When i come across a number using method Character.isDigit() it works fine for numbers from 0 - 9 but when there is number like 100 it doesnt read it.. how can i get passed my problem?
public int[][] readFile(){
file = new File("somefile.txt");
if(file.exists()){
System.out.println("Exists");
}
FileInputStream inputFile;
Reader reader;
boolean isTrue = true;
int i,j;
i = -1;
j = -1;
try{
inputFile = new FileInputStream(file);
reader = new InputStreamReader(inputFile);
int index;
//the while loop;
try {
while((index = reader.read()) != -1){
char current = (char) index;
if(Character.isLetter(current)){
//do nothing
// System.out.print(c);
}
else if(Character.isDigit(current) && isTrue){
String s = current + "";
int x = Integer.parseInt(s);
a = new int[x][x];
isTrue = false;
}
else if(current == ','){
j++;
}
else if(current == '\n'){
i++;
}
else if(current == ' '){
}
else if(j > 7){
j = 1;
}
else if(Character.isDigit(current)){
String s = current + "";
int value = Integer.parseInt(s);
// System.out.println(i + " " + j);
a[i][j] = value;
}
else{
//do nothing
}
}//end while loop
} catch (IOException e) {
System.out.println("IOException occured");
}
}catch(FileNotFoundException e){
System.out.println("Exception has occured");
}
return a;
}

New Topic/Question
Reply




MultiQuote



|