I know that there are already a bunch of questions about this on StackExchange but I've already tried a couple of suggestions and I can't seem to find the right solution for me.
What I want to do: I copied the file test.txt into the folder "test" (normal External Storage, no additional SD card) on my phone using my PC and now I want to read the content of the file again, copy everything into a String and do more stuff with it.
On my PC the path of the file is: Computer\Samsung Galaxy S7\Phone\test\test.txt On the phone it's: My Files\Device Storage\test\test.txt
My code:
String root = Environment.getExternalStorageDirectory().getAbsolutePath().toString();
String path = root + File.separator + "test" + File.separator + "test.txt";
File f = new File(path);
StringBuilder sb = new StringBuilder();
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader(f));
String line;
while ((line = br.readLine()) != null) {
sb.append(line);
sb.append('\n');
}
text = sb.toString();
br.close();
} catch (IOException e) {
return path;
}
The problem is that it always gets into the "catch" part and then returns "Storage/emulated/0/test/test.txt", which apparently isn't the right path (otherwise it should have found the file).
If I use
File f = Environment.getExternalStoragePublicDirectory("test" + File.separator + "test.txt");
it results in the same thing.
What did I miss/what do I have to use, so it finds the file?