aspose file tools*
The moose likes I/O and Streams and the fly likes how to write a new line on a file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "how to write a new line on a file" Watch "how to write a new line on a file" New topic
Author

how to write a new line on a file

Arjun Bajaj
Greenhorn

Joined: Apr 21, 2010
Posts: 13
I was making a program and i wanted it to save entered text in different lines....

My Program >>>>



I want "Hello" and "World" to come in 2 different lines...... I tried doing writeln but that didn't work.........


So what should i do to get Hello and World in two different lines
Pramod P Deore
Ranch Hand

Joined: Jul 15, 2008
Posts: 629

You can use PrintWriter as


If you want to write on same line use print() instead of println ()


Life is easy because we write the source code.....
Arjun Bajaj
Greenhorn

Joined: Apr 21, 2010
Posts: 13
Hey....thanks Pramod......i tried it and it worked......thanks.......
Arjun Bajaj
Greenhorn

Joined: Apr 21, 2010
Posts: 13
Hey, Actually I forgot to ask one more thing......How should i save the file which is created in a different directory under my home directory.......thanks....
Pramod P Deore
Ranch Hand

Joined: Jul 15, 2008
Posts: 629

you can set the path of file
PrintWriter out = new PrintWriter(c:/deore/Hotel1.txt); //this will create Hotel.txt file under deore directory.(but deore folder must be exist under c directory)
Arjun Bajaj
Greenhorn

Joined: Apr 21, 2010
Posts: 13
Hey......I'm using ubuntu and in that i tried to do so when i do this the compiler gives me an error of illegal start of expression...... what should i do.....and i dont think its the problem of my os.......it will give me this error everywhere.........

so what should i do to fix this.......

thnx.......
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19719
    
  20

Turn the arguments to that constructor into a proper String.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to write a new line on a file