Friday, 6 September 2013

extract a int from a file using multiple delimeters

extract a int from a file using multiple delimeters

I have a text file:
90,-5 ,, 37 , 1 99
0 -55,,,
,,,11
I need to extract the integers into an array. I have been traing to do so
with this code:
File file=new File("2.txt");
Scanner in=new Scanner(file);
in.useDelimiter(" *|,*|\\n");
int[] b=new int[20];
int i=0;
while(in.hasNextInt()){
b[i]=in.nextInt();
i++;
}
in.close();
What i doing wrong?

No comments:

Post a Comment