Home  >  Q&A  >  body text

java - 怎么替换读到的文件流里面的内容?

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

巴扎黑巴扎黑2764 days ago388

reply all(2)I'll reply

  • PHP中文网

    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.

    reply
    0
  • 黄舟

    黄舟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

    reply
    0
  • Cancelreply