我正在使用Android studio来开发我的Android应用程序。我已经在子文件夹red_voznje的资产文件夹中创建了我在安卓工作室中使用的文件。这是我的代码
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基本相同,我只是将resault保存在TimeMinFromSmb而不是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){}
}
smbzag 和 zagsmb 都存在于资产文件夹中,但 smbzag 未打开,停止从资源管理器创建输入流。我该怎么做才能解决这个问题?
确保您正在拨打电话
从您的活动中获取资产()。
否则,您可以尝试此解决方案:
https://stackoverflow.com/a/9544777/3108270
确保创建了 assets 文件夹,并将所有文件(具有以下行指定的路径)放在 app.iml 文件中的应用目录中。
<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
我已经删除了所有资产并使用Windows资源管理器将它们添加到资产目录中,并添加了扩展.txt