2

I am struggling with this problem. I do not know where to put my file so that it can be visible when installing the apk

char s1[10];
        FILE *infile, *fopen();
        infile = fopen("/data/data/com.example.hellojni/files/datain.txt","r");

        if (NULL == infile)
        {

            return (*env)->NewStringUTF(env, "***can't find the file");
        }
        fgets(s1,9,infile);
        return (*env)->NewStringUTF(env,s1 );

I have no idea where to put my datain.txt. I put it in the bin folder but it isn't working. I keep saying can't find the file. The path is correct because I print it out on my screen.

Help pls,

Thanks. enter image description here

Lan Nguyen
  • 329
  • 1
  • 3
  • 10

1 Answers1

1

The most reliable approach I know about is:

First, in your Java code, store the file from your assets to some directory of the application, then pass the path of the file to the native function.

MByD
  • 135,866
  • 28
  • 264
  • 277
  • I put my file in asset folder too, but how do I get the path of my assetfolder. I am trying to avoid using asset Manager, or at least from my jni side – Lan Nguyen Nov 23 '12 at 22:59
  • you cannot read it directly from there, you need to copy it to one of the application folders first. – MByD Nov 23 '12 at 23:01
  • I put my directory level in my post, where would be good to put my file? – Lan Nguyen Nov 23 '12 at 23:06
  • take a look here: http://stackoverflow.com/questions/5527764/get-application-directory – MByD Nov 23 '12 at 23:22
  • I do not want to put it manually in my phone, I want the file to be extract from apk upon the installation. – Lan Nguyen Nov 23 '12 at 23:48
  • @LanNguyen there is no such feature. http://stackoverflow.com/questions/13317387/how-to-get-file-in-assets-from-android-ndk – auselen Nov 24 '12 at 08:26