0

In my eclipse, I have a Java project (let's name it project A). This project has a folder "dic", with some files in it, and I use this code to access those files:

    File[] listOfFiles = new File("dic").listFiles(); 
    for (int i = 0; i < listOfFiles.length; i++) { (...)

This works perfectly when executed in project A.

Now I need to use the classes in project A in an Android project (project B). I've included project A in project B's build path, and I get no compilation errors.

But when I try to execute the code above in an Android device, it seems to be checking the phone filesystem instead of the filesystem on project A, so it can't find the files.

How can I access the files in project A from project B? Is there a way to replace the code in project A so it can be used directly both in project A and B?

Alan
  • 211
  • 2
  • 13
  • 2
    Unlikely as the Android app runs on a different machine (android device in this case). Yuo would need to include the "dic" folder in the android proyect somehow or sotre them in a server and read them from the server. – s1m3n Jan 30 '14 at 15:38

1 Answers1

0

Copy the dic folder from Project A to the assets folder. and access the folder from there as the filesystem of project A is the harddisk of your computer while android reads the filesystem from the mobile

    Resources res = getResources(); //if you are in an activity
    AssetManager am = res.getAssets();
    String fileList[] = am.list(dirFrom);

    if (fileList != null)
    {   
        for ( int i = 0;i<fileList.length;i++)
        {
           Log.d("",fileList[i]); 
        }
    }

this code is from old question android list files contained in assets subfolder

Community
  • 1
  • 1
youssefhassan
  • 1,067
  • 2
  • 11
  • 17
  • I had thought of something quite similar to that (although I appreciate the answer, because I'm still new to Android and I'm learning to work with android resources), but I see two problems for that solution: I need the files in two places, and I need different methods for Java and Android. Is there any way to avoid that? – Alan Jan 30 '14 at 20:48