public String getXmlString() {
String xmlString;
byte[] strBuffer = null;
int flen = 0;
File xmlfile = new File("/data/local/getHomePage.xml");
try {
InputStream in = new FileInputStream(xmlfile);
flen = (int)xmlfile.length();
strBuffer = new byte[flen];
in.read(strBuffer, 0, flen);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
xmlString = new String(strBuffer); //构建String时,可用byte[]类型,
return xmlString;
}
本文介绍了一种从本地文件系统中读取XML文件的方法,并通过Java代码实现了将XML文件的内容转换为字符串的过程。该方法使用FileInputStream进行文件读取,并通过byte数组存储文件内容。
521

被折叠的 条评论
为什么被折叠?



