Quantcast
Channel: OpenCV Q&A Forum - RSS feed
Viewing all articles
Browse latest Browse all 41027

Cannot open file through JNI

$
0
0
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?

Viewing all articles
Browse latest Browse all 41027

Trending Articles