java - 怎么替换读到的文件流里面的内容?
巴扎黑
巴扎黑 2017-04-18 10:07:32
0
2
358

需要实时替换读到已经生成的静态页中的某些东西,代码如下;
FileInputStream ff = new FileInputStream(file);
byte[] data = new byte[(int) f.length()];
ff.read(data);
String str2=new String(data);
但是转换后,str2 输出的就是全部已生成的静态页的代码,但是用str2.replace替换不起作用?这是为什?要怎么才能替换读到的file里面的某些东西?

巴扎黑
巴扎黑

reply all(2)
洪涛

The replace method returns a new String instead of replacing the original string. You can directly obtain the replaced string through str2.replace() or use s to receive it like String s=str2.replace() above. The replaced string.

黄舟

Look at the API
String str=str2.replace(reg,newStr);
No characters are received after replacement, it definitely doesn’t work, the original str2 is still unchanged

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!