【问题标题】:Android: Cannot find plist in res/raw using xmlwiseAndroid:无法使用 xmlwise 在 res/raw 中找到 plist
【发布时间】:2013-03-02 23:54:03
【问题描述】:

我正在尝试使用 xml 方式将 plist 读入我的 android 应用程序。这是我的代码

String path = "android.resource://" + context.getPackageName() + "/" + R.raw.nameofplist;
Map<String, Object> males = Plist.load(path);

但我不断得到:

java.io.FileNotFoundException: /android.resource:/com.packagename.appname/2130968577 (No such file or directory)

在我的res/raw 文件夹中获取我的 plist nameofplist.plist 的路径的正确方法是什么?

【问题讨论】:

    标签: android xml-parsing plist


    【解决方案1】:

    我也很难找到答案……但我最终解决了。

    这是我的解决方案,它基于一个名为 airports.plist 的 plist 文件,该文件位于 res/raw 文件夹中。

    Map<String, Object> properties = null;
    try {
        InputStream inputStream =getResources().openRawResource(R.raw.airports);
        BufferedReader br = null;
        try {
            br = new BufferedReader(new InputStreamReader(inputStream));
            StringBuilder sb = new StringBuilder();
            String line;
            while ((line = br.readLine()) != null) {
                sb.append(line);
            }
            properties = Plist.fromXml(sb.toString());
    
            //TODO do something with the object here
            System.out.println("plist object... "+properties);
    
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            br.close();
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    

    希望这对某人有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多