java 读取文件转为字符串
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;
}
本文提供了一个使用Java从文件中读取数据并将其转换为字符串的示例。该示例展示了如何打开指定路径的XML文件,读取其全部内容,并将读取到的字节转换为字符串。
522

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



