This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Need Printwriter help!!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Need Printwriter help!!!!" Watch "Need Printwriter help!!!!" New topic
Author

Need Printwriter help!!!!

Ken Tab
Greenhorn

Joined: Jul 05, 2002
Posts: 3
Howdy partners,
Trying to do some file inpu/output with java (am I crzay or what!)
Anyway here is my print method:
-------------------------------
public String printFinishQ()
{
for (int i = 0; i < nextJob; i++)
{
output += theQueue[i].getJobnumber()
+ " "
+ theQueue[i].getOgtime()
+ " "
+ theQueue[i].getFinishtime()
+ " "
+ (theQueue[i].getFinishtime()-theQueue[i].getOgtime())
+ " "
+ "\n";
}
return output;
}
-------------------------------
And here is where it's being called:
-------------------------------
fout.println( "JobID RunTime TimeAccrued " );
fout.println( "===================================" );
fout.println( out.cpu.readyQ.FinishQ() );
fout.println( "" );
fout.println( "" );
-------------------------------
Well, the problem is that my print method creates a string with many separate lines but when I try to write it to a file using fout.println, the string is displayed all in ONE line!!!
How can I make it so fout.println displays the string as I want, on separate lines???
Thanks in advance,
Ken
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
If I recall correctly: UNIX systems require "\n" (new line) character to display a new line. Mac systems require a "\r" (carriage return) character to display a new line. Windows systems require both - "\n\r" (the order may be backwards, so Windows may require "\r\n").
Off hand I don't remember if println displays "\n" only or if it displays different new line characters depending on the OS on which it is running.
Perhaps explicitly specifying both the newline and return characters in order to display a new line would solve the problem.
Any luck?


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Ken Tab
Greenhorn

Joined: Jul 05, 2002
Posts: 3
"\r\n" worked!!!
Thanks!!!
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Great!
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 984

I thought the correct way of doing this was to use

and that you didn't want to use control characters, like "\n", as they were platform dependent.


Please ignore post, I have no idea what I am talking about.
Rishi Tyagi
Ranch Hand

Joined: Feb 14, 2002
Posts: 100
I think willims is right,
As a matter of fact if we get return the system propery line.separator and use it in place of specified line feed characters which are system dependent then we will not have to bother about the O/S used for the application and it will give a generalised solution.
Rishi
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
That should work well as well and to accomplish platform independence, is perhaps the best solution.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need Printwriter help!!!!
 
Similar Threads
Pretty Print SOAP message
Declaring a PrintWriter object
Eclipse Remote Debugging
Socket problem
Buffered Reader problems