well, i have that, my request is to read only the numbers of a file, but i stuck in the exception, i can manage the exc but i dont know how to do when in the reading of the file there are a word and excp work, because i want that program dont finish and continue reading until the end.
Eg:
" 5 March of 2012" i want to obtain only 5 and 12 but when i try to pass March whtth Integer.valueOf ( i need onl numbers because i must use them for things after)the exception go and dont read 2012 i want read 2012 too. but only 5 an 2012
Code:import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.StringTokenizer;
public class Open {
private static ArrayList<String> cadFile = new ArrayList<String>();
private static ArrayList<Integer> numInt = new ArrayList<Integer>();
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
File f = null;
javax.swing.JFileChooser cuadro = new javax.swing.JFileChooser();
cuadro.showOpenDialog(cuadro);
String path = cuadro.getSelectedFile().getAbsolutePath();
FileReader fileReader = null;
BufferedReader bufferedReader = null;
f= new File(path);
try{
fileReader = new FileReader(f);
bufferedReader = new BufferedReader(fileReader);
String L;
while((L = bufferedReader.readLine()) != null) {
cadFile.add(L);
}
for(int j = 0; j<cadFile.size(); j++) {
String lineaArchivo = cadFile.get(j);
StringTokenizer line = new StringTokenizer(lineaArchivo);
int numeroElementosLinea = line.countTokens();
for(int k = 0; k<numeroElementosLinea; k++) {
numInt.add(Integer.parseInt(line.nextToken()));
}
}
System.out.println(numInt);
}
catch(Exception e){
}
finally{
try{
if(fileReader != null) {
fileReader.close();
}
}
catch(Exception e2){
}
}
}
}
