System_Error
May 21st, 2005, 03:20 PM
How can you read a certain line from a file without wasting your time processing each line like this:
try {
BufferedReader in = new BufferedReader(new FileReader("infilename"));
String str;
while ((str = in.readLine()) != null) {
process(str);
}
in.close();
} catch (IOException e) {}
Like, if I had a list of 5000 words, and I wanted to skip to the 1234th word, how would I do that? I know I could use a counting variable in the above example, but I wouldn't want to keep reading everyline like that untill I got to the right one.
try {
BufferedReader in = new BufferedReader(new FileReader("infilename"));
String str;
while ((str = in.readLine()) != null) {
process(str);
}
in.close();
} catch (IOException e) {}
Like, if I had a list of 5000 words, and I wanted to skip to the 1234th word, how would I do that? I know I could use a counting variable in the above example, but I wouldn't want to keep reading everyline like that untill I got to the right one.