无法访问assets子文件夹中的文件

时间:2015-01-15 03:21:02

标签: android file text assets subdirectory

我正在使用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”时,我得到一个未找到execption的文件。

任何人都知道发生了什么事吗?我错过了什么吗?

谢谢!

1 个答案:

答案 0 :(得分:1)

Android是基于Linux的 - 使用正斜杠而不是反斜杠。所以,sub/file2.txt