0

I create this method to create a new file and write a file to a folder called "MPS 3000". But when I run my application, I can't see anything changed in my android device. Is there anything wrong? Thanks.

public void WriteToFile(String sBody) {
    //SimpleDateFormat formatter = new SimpleDateFormat("yyyy.MM.dd G 'at' HH:mm:ss z");
    //Date present = new Date();

String fileName = "mps.txt";

    try {
        File root = new File(Environment.getExternalStorageDirectory(), "MPS3000");
        if (!root.exists()) {
            root.mkdirs();
        }

        File mpsfile = new File(root, fileName);

        FileWriter writer = new FileWriter(mpsfile, true);
        writer.append(sBody + "\n\n");
        writer.flush();
        writer.close();
        Toast.makeText(this, "Saved...", Toast.LENGTH_SHORT).show();

    } catch (IOException e) {
        e.printStackTrace();

    }
}
James
  • 11
  • 3
  • 2
    https://stackoverflow.com/questions/32789157/how-to-write-files-to-external-public-storage-in-android-so-that-they-are-visibl – CommonsWare Jul 24 '17 at 20:45
  • I don't quite know how to use the scanFile method. I don't define Context, so what I should input in the Context variable – James Jul 24 '17 at 21:03
  • Your `Activity` or `Service` is your `Context` for the purposes of that code. – CommonsWare Jul 24 '17 at 21:05

0 Answers0