【发布时间】:2015-03-13 10:12:13
【问题描述】:
我正在使用 Andriod Studio 开发应用程序,但在访问我的资产子文件夹时遇到了一些问题。 当我尝试访问资产根文件夹中的文件(例如 file1)时,像这样
AssetManager assetMng = getAssets();
InputStream textoInput;
String path = "file1.txt";
try {
textoInput = assetMng.open(path);
BufferedReader r = new BufferedReader(new InputStreamReader(textoInput));
StringBuilder total = new StringBuilder();
String line;
while ((line = r.readLine()) != null) {
total.append(line);
}
} catch (IOException e){
lista.add("Exception: " + e.toString());
e.printStackTrace();
}
我成功获取文本。但是当我将“file1.txt”更改为“sub\file2.txt”时,我得到一个文件未找到执行。
有人知道发生了什么吗?我错过了什么吗?
谢谢!
【问题讨论】:
标签: android file text assets subdirectory