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();
}
}