I am using Android Studio to try to write a file to external storage.
Other posts recommended that I do this with getExternalFilesDir(null) , but I get the Cannot resolve method 'getExternalFilesDir(null)' message Cannot resolve method 'getExternalFilesDir(null)' .
public void makeFile() { try { String storageState = Environment.getExternalStorageState(); if (storageState.equals(Environment.MEDIA_MOUNTED)) { File file = new File(getExternalFilesDir(null), "outputFile.txt"); FileOutputStream fos = new FileOutputStream(file); String text = "Hello, world!"; fos.write(text.getBytes()); fos.close(); } } catch (Exception e) { e.printStackTrace(); } }
I could not find a way to get rid of this error. Thanks in advance for any solutions to the problem.
source share