So My code looks like this:
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
}
}
I get right form of output at line System.out.println(m.group(1));
However when I later on want to write what is shown by m.group(1)
It writes to file without putting linebreak since the code doesn't have one.
Just call fw.write(System.getProperty("line.separator"));
.
System.getProperty("line.separator")
will give you the line separator for your platform (whether Windows or some Unix flavor).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With