gpt4 book ai didi

android - 从抛出 FileNotFoundException 的 Assets 中读取文件

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:57:28 24 4
gpt4 key购买 nike

我正在使用以下代码:

    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 文件夹中的文本文件。感谢任何帮助

安迪

最佳答案

试试这个方法:

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

关于android - 从抛出 FileNotFoundException 的 Assets 中读取文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14580385/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com