为什么Android没有在资产中看到现有文件?

时间:2015-06-18 11:25:20

标签: android file assets

我使用Android工作室开发我的Android应用程序。我在子文件夹red_voznje中的Assets文件夹中创建了我在android studio中使用的文件。 这是我的代码

            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);

这里是GetToTime函数和GetFromTime基本相同我只是在TimeMinFromSmb而不是TimeMinToSmb中保存了resault

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){}
}

smbzag和zagsmb都存在于Assets文件夹中,但smbzag未在资产管理器创建InputStream时停止。我该怎么做才能解决这个问题?

3 个答案:

答案 0 :(得分:0)

确保您正在拨打电话

来自您活动的getAssets()。

否则你可以尝试这个解决方案:

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

答案 1 :(得分:0)

确保您创建了资源文件夹,并将所有文件放在 app 目录中的 app.iml 文件中,并使用以下行指定的路径。< / p>

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

答案 2 :(得分:0)

我已删除所有资源,并使用Windows资源管理器将其添加到资源目录中,并添加了扩展名.txt