File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes I/O and Streams and the fly likes insert new line character Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "insert new line character" Watch "insert new line character" New topic

insert new line character

etrivelli nainar

Joined: Feb 14, 2002
Posts: 5
Hi, I'm creating a batch file with two commands in it. I would like to insert a nextline character between these two commands. How do I do that?
jason adam
Chicken Farmer ()
Ranch Hand

Joined: May 08, 2001
Posts: 1932
Welcome to the JavaRanch! Please adjust your displayed name to meet the JavaRanch Naming Policy. You can do so here.
Thanks! and again, Welcome to the Ranch!
Rene Liebmann
Ranch Hand

Joined: May 02, 2002
Posts: 196
try to add "\n\r" or "\r\n" between the lines.
Basicly, this is OS dependent. On Windows, it should be enough, to add "\n", but not on Unix systems.
Good luck

jason adam
Chicken Farmer ()
Ranch Hand

Joined: May 08, 2001
Posts: 1932
Also, if you are talking about inserting the character just so you have the commands on separate lines, like:
command one
command two
you can use the PrintWriter class, it has options to write both on the same line (the print() method), or write one command on one line, and then the next on a new line (the println() method).
You would create the object like this:
PrintWriter write = new PrintWriter( new FileOutputStream( "filename.bat" ) );
And simply call:
write.println( "command one" );
write.println( "command two" );
If you want a whole separate line, something like:
command one
command two
Then you could make three calls like:
write.println( "command one" );
write.pritnln( "command two" );
Look at the API for the IO classes, plenty of things there to handle this.
I agree. Here's the link:
subject: insert new line character
It's not a secret anymore!