gpt4 book ai didi

java - Android 库无法读取 openRawResource 提供的流

转载 作者:行者123 更新时间:2023-11-30 04:32:11 27 4
gpt4 key购买 nike

我正在使用 plist 库加载一个 plist 文件:http://code.google.com/p/plist/我正在使用这样的代码:

//InputStream ins = getResources().openRawResource(R.raw.skillsanddrills)
InputStream ins = getResources().openRawResource(R.xml.skillsanddrills); //file name is skillsanddrills.plist
NSDictionary rootDict;
try {
rootDict = (NSDictionary)PropertyListParser.parse(ins);
...

但是我得到:

java.lang.UnsupportedOperationException: The given data is neither a binary nor a XML property list. ASCII property lists are not supported.

我不认为这是库的错误,因为我在使用另一个 plist 库时遇到了类似的错误,并且文件本身只是一个计划 XML 结构。为什么 Android 会更改我的 plist 文件?关于如何解决此问题的任何想法?

该库还接受文件而不是流。但无法弄清楚如何创建文件的文件路径。

最佳答案

这应该是崩溃的源代码:

/**
* Parses a property list from a file. It can either be in XML or binary format.
* @param f The property list file
* @return The root object in the property list
* @throws Exception If an error occurred while parsing
*/
public static NSObject parse(File f) throws Exception {
FileInputStream fis = new FileInputStream(f);
String magicString = new String(readAll(fis, 8), 0, 8);
fis.close();
if (magicString.startsWith("bplist00")) {
return BinaryPropertyListParser.parse(f);
} else if (magicString.startsWith("<?xml")) {
return XMLPropertyListParser.parse(f);
} else {
throw new UnsupportedOperationException("The given data is neither a binary nor a XML property list. ASCII property lists are not supported.");
}
}

也许你不应该把你的 plist 放在 xml 中,而是放在 raw 文件夹中,然后像这样加载它:

getResources().openRawResource(R.raw.skillsanddrills)

如果失败,将其放入 asset 并像这样加载它:

getAssets().open("filename");

如果失败,那么你的 plist 可能只是格式错误。

关于java - Android 库无法读取 openRawResource 提供的流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7507728/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com