FileWriter is not writing in to a file

后端 未结 5 1004
谎友^
谎友^ 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:21

    You must close the FileWriter, otherwise it won't flush the current buffer. You can call the flush method directly..

    fileWriter.flush()
    fileWriter.close()
    

    You don't need to use the flush method if you are closing the file. The flush can be used for example if your program runs for a while and outputs something in a file and you want to check it elsewhere.

提交回复
热议问题