I have been trying to write to a file in Android. It is not working and it doesn't even create a file. It always executes the catch block. Here is the part of my program.
private void write(){
try {
FileWriter fileWriter = new FileWriter("C:\\Users\\Administrator\\AndroidStudioProjects\\SunCalculator\\app\\src\\main\\res\\raw\\au_locations.txt");
Log.e("Data","path detected");
BufferedWriter bfWriter = new BufferedWriter(fileWriter);
bfWriter.write("Text Data");
bfWriter.close();
Log.e("Data","worked");
} catch (IOException e) {
e.printStackTrace();
Log.e("Data","not worked");
}
}
I also tried to create a File
object and passing it to the FileWriter
constructor. None of these worked. I am using Android Studio 2.3.3
C:\Users\Administrator
is write-enabled.