1

I am new to the android studio. I want to create a folder and related files to receive the data sent from a MPS 3000 machine. So I write the function follow some instructions. However, when I run the application, I could not find the file I create. Is there anything wrong with my code? Or how I can find the file I created?

public void WriteToFile(String sBody)
{
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy.MM.dd G 'at' HH:mm:ss z");
    Date present = new Date();
    String fileName = formatter.format(present) + ".txt";//2017.07.06 AD at 12:08:56 PDT

    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
  • https://stackoverflow.com/questions/32789157/how-to-write-files-to-external-public-storage-in-android-so-that-they-are-visibl – CommonsWare Jul 11 '17 at 20:48

0 Answers0