FileWriter is not writing in to a file

后端 未结 5 1001
谎友^
谎友^ 2021-01-15 09:04

I have below code

    try
    {
        FileWriter fileWriter = new FileWriter(\"C:\\\\temp\\\\test.txt\");
        fileWriter.write(\"Hi this is sasi This t         


        
5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-15 09:37

    Please try this :

      try
        {
            FileWriter fileWriter = new FileWriter("C:\\temp\\test.txt");
            fileWriter.write("Hi this is sasi This test writing");
            fileWriter.append("test");
            fileWriter.flush(); // empty buffer in the file
            fileWriter.close(); // close the file to allow opening by others applications
        }
        catch(IOException ioException)
        {
            ioException.printStackTrace();
        }
    

提交回复
热议问题