我已经从.txt文件中读取了以下内容:
但是在阅读并输出后,我得到了:
null<?xml version="1.0"?>
开头为null,这是方法:
public class Filer {
private static String str;
public static String read(String file) {
BufferedReader br = null;
try {
String sCurrentLine;
br = new BufferedReader(new FileReader(file));
while ((sCurrentLine = br.readLine()) != null) {
str += sCurrentLine;
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (br != null)br.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
return str;
}
}
返回的字符串由其输出 System.out.println
我尝试按str.indexOf("null");或检查该字符串,str.indexOf("\0");但得到-1
有想法该怎么解决这个吗?