Click here to Skip to main content
15,887,376 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Last time i was able to save it on my file manager and last week when i try to save it again. I have an error this is my android manifest

android manifest.xml:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE">

My Activty codes:

FileWriter fileWriter = null;
String address = "/sdcard/GPSTracker.txt";
try {
fileWriter = new FileWriter(address, true);
} catch (IOException e) {
e.printStackTrace();
}

BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
String str1 = textLatLong.getText().toString().trim();
String use1 = username.getText().toString();

//Add new line for existing textfile
try {
// First, read the lines
List<object> lines = Files.lines(Paths.get(address)).collect(Collectors.toList());
long count = lines.size();
bufferedWriter.write(count + "," + serialNumber + "," + use1 + "," + str1 + "," + filename1);
bufferedWriter.newLine();
} catch (IOException e) {
e.printStackTrace();
}
try {
bufferedWriter.close();
} catch (IOException e) {
e.printStackTrace();
}

Toast.makeText(MainActivity.this, "Sucessfully Saved", Toast.LENGTH_SHORT).show();

What I have tried:

I tried any method as far as i could but this is always an error.

W/System.err: java.io.FileNotFoundException: /sdcard/GPSTracker.txt (Permission denied)
at java.io.FileOutputStream.open0(Native Method)
Posted
Comments
David Crow 6-Apr-20 10:05am    
Which of the two exceptions is being thrown, the first or the second?
Member 14771791 7-Apr-20 21:44pm    
the second one
David Crow 8-Apr-20 8:07am    
Using the debugger, you need to step through those four statements and find the exact one that is throwing the exception. To that end, you might want to break that first statement up into its individual pieces (rather than lump it all together).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900