Format difference in System.out Vs. file output
In my program I print the results and output them to a file. The format of the output is different. Can someone tell me why and how I can
make the output to file the same format as the print output.
here is the code:
Code :
PrintWriter outFile = new PrintWriter("C:\\users\\remo\\downloads\\Ch3_Ex7Output.txt");
outPut = e1FirstName + " " + e1LastName + " " + String.format("%.2f", employee1Final) + "\n" +
e2FirstName + " " + e2LastName + " " + String.format("%.2f", employee2Final) + "\n" +
e3FirstName + " " + e3LastName + " " + String.format("%.2f", employee3Final) + "\n";
System.out.printf(outPut);
outFile.printf(outPut);
inFile.close();
outFile.close();
Here is the print output:
Code :
Andrew Miller 3289.49
Sheila Green 4553.55
Amit Sethi 4568.93
here is the file output:
Code :
Andrew Miller 3289.49Sheila Green 4553.55Amit Sethi 4568.93
Thanks!
Re: Format difference in System.out Vs. file output
I answered this question in Your other post.
Re: Format difference in System.out Vs. file output
What program are you using to view the file? Notepad and Wordpad will give different results.
Look at the files properties to see how many bytes are in the file.
Does that number match what you see when you look at the text of the file in a viewer?
I suspect the file has 3 or 4 more bytes than you see in the editor or viewer.
Use the String.length() method to print out the length of the String before writing it to the file.