How do I write to a .txt file in Android?

后端 未结 2 689
长情又很酷
长情又很酷 2020-12-09 18:29

I have an app that needs to read and write to a text file. I have it reading, but I don\'t have it writing. The idea is that when I click the save button on the screen, its

2条回答
  •  一整个雨季
    2020-12-09 19:03

    with mari's solution i was getting

           java.lang.IllegalArgumentException: contains a path separator
    

    then i tried following and it worked for me

      File root = new File(DIRECTORY_PATH);
      File gpxfile = new File(root, "samples.txt");
      FileWriter writer = new FileWriter(gpxfile);
      writer.append("First string is here to be written.");
      writer.flush();
      writer.close();
    

    you can loop it to write multiple lines

提交回复
热议问题