0

I have some java code:

public void writeToFile(String data, Context ctx) {
    String path = Environment.getExternalStorageDirectory().getAbsolutePath();
    File tempFile = new File(path, "houseDataFile.txt");
    try
    {
        FileOutputStream fOut = new FileOutputStream(tempFile);
        fOut.write(data.getBytes());
        fOut.close();
        Toast.makeText(ctx, "Saved", Toast.LENGTH_SHORT).show();
    }catch (Exception e)
    {
        Log.w(TAG, "FileOutputStream exception: - " + e.toString());
    }
}

When I call this function it makes the Toast and says "Saved", but then when I go to my external storage on the device, the file is non existent, and my app directory is not there. Can anyone give me some pointers as to why nothing is actually being created?

Pixelknight1398
  • 537
  • 2
  • 10
  • 33
  • 2
    https://stackoverflow.com/questions/32789157/how-to-write-files-to-external-public-storage-in-android-so-that-they-are-visibl – CommonsWare Feb 08 '17 at 17:05
  • Thank you that worked, strangely enough using the mediascanner method it actually pulled it up in my internal storage? even though the point was to get it in the external. Either way I'm happy but still confused??? – Pixelknight1398 Feb 08 '17 at 17:15
  • 1
    You cannot see what the Android SDK refers to as [internal storage](https://commonsware.com/blog/2014/04/07/storage-situation-internal-storage.html). You are seeing what the Android SDK refers to as [external storage](https://commonsware.com/blog/2014/04/08/storage-situation-external-storage.html). Google uses different terms with users and developers; the linked-to blog posts go into more detail about each. – CommonsWare Feb 08 '17 at 17:22

0 Answers0