How to write content on a text file using java?

前端 未结 3 1112
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-15 09:58


i am having a program in java.which system.out some strings,i need to save each of them in a text file
it is showing in a format
ruo1 row2 row3
i want it in

3条回答
  •  天涯浪人
    2021-01-15 10:50

    Very quick code. I apologize if there are compile errors.

     import java.io.FileWriter;
      import java.io.IOException;  
      public class TestClass {
          public static String newLine = System.getProperty("line.separator");
          public static void main(String[] a) {
            FileWriter writer;
            try {
              writer = new FileWriter("test.txt");
              for(int i=0;i<3;i++){
                writer.write(row+i+newLine);
              }
              writer.close();
            } catch (IOException e) {
              e.printStackTrace();
            }
    
          }
        }
    

提交回复
热议问题