【问题标题】:Can't access file in assets subfolder无法访问资产子文件夹中的文件
【发布时间】: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


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-21
      • 2017-12-11
      • 1970-01-01
      • 2014-05-04
      • 1970-01-01
      • 2012-05-13
      相关资源
      最近更新 更多