我正在使用以下代码:
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());
}
}
代码提供了FileNotFoundException。我见过一些类似的问题,但我不太清楚如何解决它。该文件是assets文件夹中的文本文件。任何帮助表示赞赏
安迪
答案 0 :(得分:3)
尝试这种方式:
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(); }