Results 1 to 3 of 3
- 05-20-2007, 09:07 PM #1
Super Moderator
- Join Date
- Apr 2007
- Posts
- 30
- Rep Power
- 0
New line or Carriage Return through FileWriter
Hello,
I am using a java.io.FileWriter object to write some stuff to a given File object at runtime.
Everything works except I can't figure how to create new lines in the resulting file. All I am wirting in it appears stuck together, even if my String contain \n or \r characters.
I use java.io.FileWriter.write(String s) method.
Thanks for any help!
- 05-20-2007, 09:10 PM #2
Member
- Join Date
- May 2007
- Posts
- 11
- Rep Power
- 0
Hi John,
You can wrap the FileWriter with a PrintWriter, and use println to write "lines" of text according to the platform it is running on.
- 05-20-2007, 09:13 PM #3levent Guest
Hi John,
You can use Hasan's way.
But note that if you are on Windows, you need \r\n, both in that order. You can use the line.separator system property to get the proper separator in a generic way. That's what PrintWriter does internally.
Similar Threads
-
Using int/int, 7/5 would return 1
By zoe in forum New To JavaReplies: 2Last Post: 12-02-2008, 11:25 AM -
Reading in data from file line by line
By bluekswing in forum New To JavaReplies: 1Last Post: 10-02-2007, 12:19 AM -
if..else..return
By mqdias in forum New To JavaReplies: 1Last Post: 08-10-2007, 04:20 PM -
Return value of method
By cachi in forum New To JavaReplies: 1Last Post: 08-01-2007, 08:23 AM -
The return type
By Marcus in forum New To JavaReplies: 1Last Post: 07-05-2007, 06:28 AM


LinkBack URL
About LinkBacks

Bookmarks