I have figured out my problem. When I converted the file path from java String to c++ char*, I used GetStringChars(), which doesn't automatically null-terminate the converted char*; so my fopen doesn't get the right file name. More information can be found from:
https://groups.google.com/group/android-ndk/browse_thread/thread/e0ab7aefb3982c45 http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4616318 On Jun 14, 2:43 pm, Frank <[email protected]> wrote: > BTW, if I don't use fopen in my native function but instead use > > File file = new File("my file path"); > InputStream fis = new FileInputStream(file); > > and read from fis, it is always fine. > > On Jun 14, 2:38 pm, Frank <[email protected]> wrote: > > > > > > > > > Hi Nikolay, > > > I don't see any crucial differences between the two kinds of files. In > > fact, for those bad ones, I can even sometimes open them correctly. > > Strange!!!! Things are just un-deterministic. I checked errno, and the > > message is "No such file or directory" (but the files are definitely > > there). > > > Frank > > > On Jun 14, 9:52 am, Nikolay Elenkov <[email protected]> wrote: > > > > On Wed, Jun 15, 2011 at 1:42 AM, Frank <[email protected]> > > > wrote: > > > > Hi All, > > > > > I am experiencing a strange problem of using fopen in native code. I > > > > have a few files in /mnt/sdcard/Download and all of them have -rw > > > > privileges. However, when I call my native function which in turns > > > > uses fopen to open them, I got null returns for some files, but valid > > > > returns for others. Why is that? Any insights? Thanks. > > > > The SD card uses FAT, so permissions shouldn't really matter. > > > Check errno in your native code to see the actual error. > > > What is the difference between the files that are OK and the > > > ones that are not? -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

