JAVA输出文件为null,从文件中读取文本后的java,打印开始时将为“ null”

我已经从.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

有想法该怎么解决这个吗?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值