Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

I am using .write("")

  Asked By: Raju    Date: Apr 01    Category: Java    Views: 1892
  

I have to write a .txt file row per row
I am using
File outputFile = new File("prova.txt");
FileWriter myout = new FileWriter(outputFile);
myout.write("X:"+Integer.parseInt(str));

I do NOT want all in a row. How can I do it?

Share: 

 

3 Answers Found

 
Answer #1    Answered By: Rachael Ferguson     Answered On: Apr 01

Your question is not clear. What dont you want all in
a row? Give us an example of what you are presently
outputting and what you would like to output.

 
Answer #2    Answered By: Muhammad Evans     Answered On: Apr 01

Then do a write("\n"); after each row. Better way would be to find the
System.property for newline
instead of using hardcoded \n. But I cannot remember right now.

 
Answer #3    Answered By: Kian Evans     Answered On: Apr 01

here is a solution,

import java.io.*;
public class FileTest
{
public FileTest()
{
try{
File outputFile = new File("prova.txt");
FileWriter myout = new FileWriter(outputFile);
for(int i=0;i<100;i++)
{
myout.write("X:"+i);
myout.write("\n");
}
myout.flush();
}catch(Exception ex){ex.printStackTrace();}
}

public static void main(String args[])
{
new FileTest();
}
}

Please open the prova.txt file  with wordpad. See you
have done it.

 
Didn't find what you were looking for? Find more on I am using .write("") Or get search suggestion and latest updates.




Tagged: