无法访问资产子文件夹中的文件
Can't access file in assets subfolder
我正在使用 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 基于 linux - 使用正斜杠而不是反斜杠。所以,sub/file2.txt
我正在使用 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 基于 linux - 使用正斜杠而不是反斜杠。所以,sub/file2.txt