FileNotFound - When trying to get asset file

时间:2016-10-20 13:16:52

标签: android eclipse

I'm trying to get a file in the assetsbut when I run my code the FileNotFound exception throws. I've checked with getAssets().list(".") and really the android does not detect the file in the assets directory, but i put the file in the assets folder. I'm not a android expert and I count with the community help to help me to understand what am I doing wrong.

Follow bellow my code:

try { 
            Log.i("PEDRO", Arrays.toString(getResources().getAssets().list(".")));
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

Result: []

try { 
            Log.i("PEDRO", Arrays.toString(getApplicationContext().getAssets().list(".")));
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

Result: []

The file is in the assets directory.

Assets

try {
            InputStream input =
                    Definitions.appContext.getAssets().open("iot.neo..........com.bks");



        } catch (IOException e) {
            e.printStackTrace();
        } 

I know that is too much important to use the Android Studio for the development of the applications, but I'm doing it on eclipse because it's a legacy code that will be changed to Android Studio before (and I'm not a responsible for that).

Thanks a lot!

1 个答案:

答案 0 :(得分:2)

Try remove ".":

        try {
            Log.d("PEDRO", Arrays.toString(getApplicationContext().getAssets().list("")));
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }