代碼為:
String str = "";
File outcontent = new File("F:" + File.separator + "example.txt");
FileInputStream in = new FileInputStream(outcontent);
int size = in.available();
byte[] buffer = new byte[size];
in.read(buffer);
in.close();
str = new String(buffer);
其中example.txt檔案中包括換行符
如果在程式末尾加入
str = str.replace("\n", "");
則str中最后一個換行\n及其之前的字符都沒有了
請問怎么才能正確替換換行符且不影響其他字符。求求大佬們答疑解惑
uj5u.com熱心網友回復:
用subString方法取出最后的字符然后置空uj5u.com熱心網友回復:
可是這樣只能把文末的換行去掉,我想做的是把所有的換行都替換成別的字串,不只是去掉
uj5u.com熱心網友回復:
那你一行行讀,然后一行行去掉轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/78917.html
標籤:Java相關
