Why is Android not seeing existing files in assets?

649 views Asked by At

I'm using Android studio to develop my android app. I have created files i use in android studio in Assets folder in sub folder red_voznje. This is my code

            fileLinija = "smbzag";
            if(TimeDay == 7) fileLinija += "sub";
            else if(TimeDay == 1) fileLinija += "ned";
            GetFromTime(fileLinija);
            fileLinija = "zagsmb";
            if(TimeDay == 7) fileLinija += "sub";
            else if(TimeDay == 1) fileLinija += "ned";
            GetToTime(fileLinija);

and for here is GetToTime function and GetFromTime is basiclly same I just save resault in TimeMinFromSmb instead of TimeMinToSmb

public void GetToTime(String file){
    AssetManager mngr;
    String red = null;
    int Timemin=0;
    int Timeh=0;
    try{
        mngr = getAssets();
        InputStream is = mngr.open(file);
        InputStreamReader isr = new InputStreamReader(is);
        BufferedReader br = new BufferedReader(isr);
        do
        {
            red=br.readLine();
            Timeh = Character.getNumericValue(red.charAt(0));
            if(Timeh == 9){
                break;
            }
            Timeh *= 10;
            Timeh += Character.getNumericValue(red.charAt(1));
            Timemin = Character.getNumericValue(red.charAt(3));
            Timemin *= 10;
            Timemin += Character.getNumericValue(red.charAt(4));
            LinijaBusaToSmb = Character.getNumericValue(red.charAt(6));
            LinijaBusaToSmb *= 10;
            LinijaBusaToSmb += Character.getNumericValue(red.charAt(7));
        }while((TimeH>Timeh)||((TimeH == Timeh)&&(Timemin<TimeMin)));//popraviti

        if(TimeMin <= Timemin) {
            TimeMinSmjerToSmb = Timemin - TimeMin;
            TimeHSmjerToSmb = Timeh - TimeH;
        }else{
            TimeMinSmjerToSmb = 60 - TimeMin + Timemin;
            TimeHSmjerToSmb = Timeh - TimeH - 1;
        }

    }
    catch (Exception e){}
}

both smbzag and zagsmb exist in Assets folder but smbzag is not opened stops on creating InputStream from asset manager. What can I do to fix this?

3

There are 3 answers

0
Matija Katanec On BEST ANSWER

I have deleted all assets and added them in assets directory using windows explorer, and added extension .txt

0
8aa8a On

Make sure you created the assets folder, and put all the files, with the path specified by the following line in app.iml file in the app directory.

    <option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
0
alDiablo On

Make sure that you are making the call

getAssets() from your activity.

Otherwise you can try this solution :

https://stackoverflow.com/a/9544777/3108270