所以我的代码如下所示:
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)
它会写入文件而不放置换行符,因为代码没有换行符。