Click to See Complete Forum and Search --> : reading into an array/writing: I/O


July 31st, 2000, 02:55 PM
Hey,
I need to read from a file and print out to a different file.. have that..
BUT how do I read
in the "input.txt" file into an array so I can process it like I would
normal command arguments.
Basically, instead of passing boat names from the command line, I read them
from a file,,, manipulate
them and then spit the results into an "output.txt" file. SO,,,, I want to
stick the input file into
an array, one word at a time,,,(jut 4 words total).. I have the following
working..
but they are not going into arrays and I am not manipulating the data other
than reading and writing.


import java.io.*;

public class ReadSource{
public static void main(String[] arg){
try{
FileReader file=new FileReader(arg[0]);
BufferedReader buff=new BufferedReader(file);
/* StreamTokenizer myData=new StreamTokenizer(new BufferedReader(file));*/
FileWriter outputtext=new FileWriter(arg[1]);
boolean eof=false;
while (!eof){
String line=buff.readLine();
if(line==null)
eof=true;
else
outputtext.write(line);
}
buff.close();
outputtext.close();
}catch (IOException e) {
System.out.println("error");
}
}
}