|
-
Nov 29th, 2005, 04:26 PM
#1
Thread Starter
Fanatic Member
Writing a file in neat format
I am using the FileWriter() class to write a file. But i'm not getting what i want.
Code:
Bill JonesJohn SmithMike BurnsDaniel MorganPeter Hughes
I dont want this, but i want this.
Code:
Bill Jones
John Smith
Mike Burns
Daniel Morgan
Peter Hughes
How can i get this? Can you get this using the FileWriter class as it doesn't appear that the class can do a carriage return when writing a file?
Last edited by x-ice; Feb 25th, 2007 at 07:09 PM.
-
Nov 30th, 2005, 12:26 AM
#2
Re: Writing a file in neat format
write a "\n" after each name
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Dec 1st, 2005, 04:17 AM
#3
Thread Starter
Fanatic Member
Re: Writing a file in neat format
 Originally Posted by ComputerJy
write a "\n" after each name
That didn't work, can you show me what you mean with example code?
-
Dec 2nd, 2005, 01:08 AM
#4
Re: Writing a file in neat format
Code:
import java.io.*;
public class Sample {
public static void main(String args[]) {
String names[] = {
"Bill Jones", "John Smith", "Mike Burns", "Daniel Morgan",
"Peter Hughe"};
FileWriter f = null;
try {
f = new FileWriter("C:\\a.txt");
for (int i = 0; i < names.length; i++) {
f.write(names[i] + " " + System.getProperty("line.separator"));
}
f.close();
}
catch (IOException ex) {
}
}
}
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|