所以我的代碼如下所示:寫入文件時插入換行符?
try {
while ((line = br.readLine()) != null) {
Matcher m = urlPattern.matcher (line);
while (m.find()) {
System.out.println(m.group(1));
//the println puts linebreak after each find
String filename= "page.txt";
FileWriter fw = new FileWriter(filename,true);
fw.write(m.group(1));
fw.close();
//the fw writes everything after each find with no line break
}
}
我得到的輸出正確的形式在行System.out.println(m.group(1));
然而,當我以後想寫什麼是m.group(1)
它寫到文件中顯示不把斷行,因爲代碼沒有按」沒有一個。
+1跨平臺思維 – MadProgrammer
好的答案! +1 –
完美:) – anno