gpt4 book ai didi

java - 使用 InputStream 读取器从/res/xml 读取 XML 文件会产生无效字符/编码数据

转载 作者:行者123 更新时间:2023-11-29 06:16:19 25 4
gpt4 key购买 nike

我在从位于/res/xml/testxml.xml 的 XML 资源中读取 XML 数据时遇到问题。出于某种原因,使用我的书中和在线示例,我无法正确读取数据。下面的方法很简单;读取 XML 资源并打印其中的行。

public InputStream fetchLocalStream(String file){
InputStream in = null;

try {
//in = Global.gContext.openFileInput("testxml.xml");
in = Global.gContext.getResources().openRawResource(R.xml.testxml);
try {
if (in != null) {
// prepare the file for reading
InputStreamReader inputreader = new InputStreamReader(in);
BufferedReader buffreader = new BufferedReader(inputreader);

String line;

// read every line of the file into the line-variable, on line at the time
while (( line = buffreader.readLine()) != null) {
Log.d(Global.TAG,"-->Line:" + line);
// do something with the settings from the file
}

}
} catch (Exception e){}


return in;
}catch (Exception e){ Log.d(Global.TAG,"--> Failed!!!!" + e); }
return in;
}

如有任何帮助,我们将不胜感激。

Line:└Ç└Ç└Ç∩┐╜∩┐╜∩┐╜∩┐╜♥└Ç└Ç└Ç#└Ç└Ç└Ƕ└Ƕ└Ç└Ç└Ç└Ç└Ç└Ç└Ç└Ç└Ç♦☺►└Ç∟└Ç└Ç└Ç
Line:└Ç└Ç└Ç∩┐╜∩┐╜∩┐╜∩┐╜$└Ç└Ç└└Ç└Ç└Ç└Ç└Ç└Ç└Ç♥☺►└Ç↑└Ç└Ç└Ç
Line:└Ç└Ç└Ç∩┐╜∩┐╜∩┐╜∩┐╜♥└Ç└Ç└Ç#└Ç└Ç└Ç☻☺►└Ç$└Ç└Ç└Ç
Line:└Ç└Ç└Ç∩┐╜∩┐╜∩┐╜∩┐╜♥└Ç└Ç└Ç%└Ç└Ç└Ƕ└Ƕ└Ç└Ç└Ç└Ç└Ç└Ç└Ç└Ç└Ç♦☺►└Ç∟└Ç└Ç└Ç
Line:└Ç└Ç└Ç∩┐╜∩┐╜∩┐╜∩┐╜&└Ç└Ç└└Ç└Ç└Ç└Ç└Ç└Ç└Ç♥☺►└Ç↑└Ç└Ç└Ç
Line:└Ç└Ç└Ç∩┐╜∩┐╜∩┐╜∩┐╜♥└Ç└Ç└Ç%└Ç└Ç└Ç☻☺►└ÇL└Ç└Ç└Ç

最佳答案

我遇到了同样的问题,并在 anddev.org 上的线程“Android SAX xml not well-formed”中找到了解决方案:

Found out an interesting stuff - when moving xml file from xml folder to raw, everything works smoothly. I guess that's why the function is called openRawResource . Anyways i think that android adds some stuff to the files stored in non raw folder. But this is just a thinking aloud.

从/res/xml 移动到/res/raw 解决了我的问题。

关于java - 使用 InputStream 读取器从/res/xml 读取 XML 文件会产生无效字符/编码数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4976038/

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