And*_*our 5 android assets filenotfoundexception
我正在使用以下代码:
public void readLevel(int line){
AssetManager am = this.getAssets();
InputStream is = null;
try {
is = am.open("levelinfo.txt");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Scanner scanner = new Scanner(is);
scanner.useDelimiter(",");
String skip;
for(int i = 1; i < line; i++){
skip = scanner.nextLine();
}
levelData = new ArrayList<Integer>();
while(scanner.hasNextInt()){
levelData.add(scanner.nextInt());
}
}
Run Code Online (Sandbox Code Playgroud)
该代码给出了FileNotFoundException。我已经看到了一些类似的问题,但是我不确定如何解决。该文件是资产文件夹中的文本文件。任何帮助表示赞赏
安迪
试试这个方法:
Run Code Online (Sandbox Code Playgroud)AssetManager assetManager = getResources().getAssets(); InputStream inputStream = null; try { inputStream = assetManager.open("levelinfo.txt"); if ( inputStream != null) Log.d(TAG, "It worked!"); } catch (IOException e) { e.printStackTrace(); }
| 归档时间: |
|
| 查看次数: |
8803 次 |
| 最近记录: |