6

我正在使用以下代码:

    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。我见过一些类似的问题,但我不太确定如何解决它。该文件是资产文件夹中的文本文件。任何帮助表示赞赏

安迪

4

1 回答 1

4

试试这种方式:

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();
    }
于 2013-01-29T10:18:00.433 回答