Posted By:
Stephen_McConnell
Posted On:
Monday, April 21, 2008 10:08 AM
I would use the java.io.BufferedReader class to manage it and if you are using a File, I would use a java.io.FileReader as my reader. One doesn't need to worry about dealing with "streams" if you do that.
Something like (there are better ways to do this... I'm using old Java 2.0 syntax):
File myFile = new File("path to file");
BufferedReader br = null;
// Somewhere here you would define your
// file output, also.
try {
br = new BufferedReader(new FileReader(myFile));
String line = null;
String words = null;
while( (line = br.readLine()) != null){
// create an array of words split by a space.
words = line.split(" ");
for(int i = 0; i < words.length; i++){
// write out the word at words[i]
}
}
}catch(IOException e){
// Handle any io exceptions.
}finally{
// close you input and output files.
}
This is
something like what one could do. You have the language take care of the messy character buffering and reading of individual characters etc etc that one would do with a stream.
Hope this helps.
Stephen McConnell