所以我的代码如下所示:
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)
它写入文件时不会放置换行符,因为代码没有换行符。
只需致电fw.write(System.getProperty("line.separator"));
.
System.getProperty("line.separator")
将为您提供适合您平台的行分隔符(无论是 Windows 还是某些 Unix 风格)。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)