Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need Printwriter help!!!!

 
Ken Tab
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Ken Tab
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"\r\n" worked!!!
Thanks!!!
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great!
 
William Barnes
Ranch Hand
Posts: 986
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rishi Tyagi
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That should work well as well and to accomplish platform independence, is perhaps the best solution.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic