I am writing a program that reads input from one file, then the program would formate the data and write it to a different file.
Input file:
Christopher kardaras,10 N Brainard,Naperville,IL,60566 George
Washington,30 W Jackson,Chicago,IL,60060
Output file:
Christopher kardaras 10 N Brainard Naperville, IL 60566
George Washington 30 W Jackson Chicago, IL 60060
when I run the code the output does not show in the output file, the following is my code.
//open input, output files
FileReader freader = new FileReader("AddressData.txt");
BufferedReader inFile = new BufferedReader(freader);
FileWriter fwriter=new FileWriter("FormattedData.text");
PrintWriter outFile= new PrintWriter (fwriter);
//process data - get a line, separate into fields, then print
//address label to the output file
line= inFile.readLine();
while (line != null)
{
//Create a new scanner, use comma as field separator
Scanner s = new Scanner(line).useDelimiter(",");
// SOME CODE OMITTED HERE FOR BREVITY
out.printf(...);
//get the next line. read failure (EOF) will exit the loop
line = inFile.readLine();
}
//clean up
inFile.close();
outFile.close();
Try flushing the outFile before closing it.
You can also use the alternative PrintWriter constructor that takes care of that for you: