Hi Guys,
How do i get my program to read in more than the first line of the file. So far it reads in all of the lines from the input file one by one and then it is meant to parse it and output all the tokens to a txt file. But at the moment it only outputs the first line. I tried putting another for loop around the while(st.hasMoreTokens()){ part but it didn't work.
here's my code...
public class Test {
public static void main(String[] args) throws IOException {
File output = new File("N:/output.txt"
;
FileWriter out = new FileWriter(output);
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(new File("N:/Printer.txt"
)));
String line = reader.readLine();
StringTokenizer st = new StringTokenizer(line, ",;:"
;
for(int i =0; line != null; i++) { //Keep on reading in lines until EOF
System.out.println(line);
line = reader.readLine(); //reading in all lines ok
while(st.hasMoreTokens()){ //while there are still tokens to read
out.write(st.nextToken()); //output token to file
} i++;
}
out.close();
}
}
How do i get my program to read in more than the first line of the file. So far it reads in all of the lines from the input file one by one and then it is meant to parse it and output all the tokens to a txt file. But at the moment it only outputs the first line. I tried putting another for loop around the while(st.hasMoreTokens()){ part but it didn't work.
here's my code...
public class Test {
public static void main(String[] args) throws IOException {
File output = new File("N:/output.txt"
FileWriter out = new FileWriter(output);
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(new File("N:/Printer.txt"
String line = reader.readLine();
StringTokenizer st = new StringTokenizer(line, ",;:"
for(int i =0; line != null; i++) { //Keep on reading in lines until EOF
System.out.println(line);
line = reader.readLine(); //reading in all lines ok
while(st.hasMoreTokens()){ //while there are still tokens to read
out.write(st.nextToken()); //output token to file
} i++;
}
out.close();
}
}