需要实时替换读到已经生成的静态页中的某些东西,代码如下;
FileInputStream ff = new FileInputStream(file);
byte[] data = new byte[(int) f.length()];
ff.read(data);
String str2=new String(data);
但是转换后,str2 输出的就是全部已生成的静态页的代码,但是用str2.replace替换不起作用?这是为什?要怎么才能替换读到的file里面的某些东西?
PHP中文网2017-04-18 10:09:32
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.
黄舟2017-04-18 10:09:32
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