First Way:
You didn’t create the directory. Also, you are passing an absolute path to openFileOutput()
, which is wrong.
Second way:
You created an empty file with the desired name, which then prevented you from creating the directory. Also, you are passing an absolute path to openFileOutput()
, which is wrong.
Third way:
You didn’t create the directory. Also, you are passing an absolute path to openFileOutput()
, which is wrong.
Fourth Way:
You didn’t create the directory. Also, you are passing an absolute path to openFileOutput()
, which is wrong.
Fifth way:
You didn’t create the directory. Also, you are passing an absolute path to openFileOutput()
, which is wrong.
Correct way:
- Create a
File
for your desired directory (e.g.,File path=new File(getFilesDir(),"myfolder");
) - Call
mkdirs()
on thatFile
to create the directory if it does not exist - Create a
File
for the output file (e.g.,File mypath=new File(path,"myfile.txt");
) - Use standard Java I/O to write to that
File
(e.g., usingnew BufferedWriter(new FileWriter(mypath))
)