• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to write a new line on a file

 
Arjun Bajaj
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 632
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use PrintWriter as


If you want to write on same line use print() instead of println ()
 
Arjun Bajaj
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey....thanks Pramod......i tried it and it worked......thanks.......
 
Arjun Bajaj
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 632
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20514
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Turn the arguments to that constructor into a proper String.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic