dkim18
asked on
writing string line by line when creating a file
Hi,
I am trying to create a file with certain string by each line. System out prints correctly, but when I see a created file it is all one line. How do I handle this?
thx,
I am trying to create a file with certain string by each line. System out prints correctly, but when I see a created file it is all one line. How do I handle this?
thx,
for(int i=0; i < listData.size(); i++){
listValue += listData.elementAt(i).toString()+"\n";
}
System.out.println("listValue: " + listValue);
fh.writeToFile(selectedFile, listValue);
...
...
public void writeToFile(File selectedFile, String value){
try {
File flt = new File(selectedFile.toString());
FileWriter wrt = new FileWriter(flt);
wrt.append(value);
wrt.flush();
sorry misread your code, you could be using the wrong line terminator for your os
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks!!
public void writeToFile(File selectedFile, String value){
try {
File flt = new File(selectedFile.toString
PrintWriter wrt = new PrintWriter(new FileWriter(flt));
wrt.println(value);
wrt.flush();