I have copied a txt file in my device's sdcard. In the Java side of my Android app (i.e. MainActivity.java) I can open the file through this code:
StringBuilder text = new StringBuilder();
try {
File sdcard = Environment.getExternalStorageDirectory();
File file = new File(sdcard,"/android-opencv/file.txt");
BufferedReader br = new BufferedReader(new FileReader(file));
String line;
while ((line = br.readLine()) != null) {
text.append(line);
text.append('\n');
}
}
catch (IOException e) {
e.printStackTrace();
}
In my cpp file I try to open the same file doing the following:
FILE* file = fopen("/storage/emulated/0/android-opencv/file.txt","r+");
if (file != NULL)
return env->NewStringUTF("Opened file");
else
return env->NewStringUTF("Error!");
I have added reading permissions in the AndroidManifest.xml:
and I have checked the file path of the external storage directory that it is "/storage/emulated/0/"
Any ideas why this might be happening?
↧