I haven't written any I/O Java code in a while, but I do remember using
java.io.PrintStream which is a buffered stream, so you don't need to create a whole mess of inline class instances.
import java.io.*;
import java.util.Scanner;
...
try {
PrintStream ps = new PrintStream(new File("file.txt"));
Scanner s = new Scanner(System.in);
String lineBuffer;
lineBuffer = s.nextLine();
ps.println(lineBuffer);
} catch (IOException ioex) {
...
} finally {
ps.close();
s.close();
}
return;
...
You may want to refine this code a little, and cover any other exceptions that may be thrown; I just wrote this out quickly and don't have time to check it, but it should work.
I haven't added any of your particulars into this, and for this I apologize, but I'm sure you can do it quite easily.
Last edited by indienick; Dec 10th, 2007 at 12:37 am.
Reputation Points: 23
Solved Threads: 2
Junior Poster in Training
Offline 71 posts
since Aug 2005