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?
Re: Writing a file in neat format
write a "\n" after each name
Re: Writing a file in neat format
Quote:
Originally Posted by ComputerJy
write a "\n" after each name
That didn't work, can you show me what you mean with example code?
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) {
}
}
}