File Writer overrides previous write Java

前端 未结 2 660
遥遥无期
遥遥无期 2021-01-23 10:22
try {
                File file = new File(filePath+\"usedcommands.txt\");
                if (!file.exists()) {
                    file.createNewFile();
                       


        
相关标签:
2条回答
  • 2021-01-23 10:52

    Use this it will work

    fw = new FileWriter("fileName",true);
    

    for more details on FileWriter see this

    0 讨论(0)
  • 2021-01-23 11:01

    Pass true as a second argument to FileWriter to turn on "append" mode.

    FileWriter fw = new FileWriter(file.getAbsoluteFile(), true);
    
    0 讨论(0)
提交回复
热议问题