I am trying to build a program in JAVA that takes data from a URL and saves it to a text file. My main problem is that my program doesn't store line changes. To be more specific here is my code:

import java.io.*;

import java.net.*;

public class Jva_Parser {

public static void main(String[] args) throws Exception {

URL oracle = new URL("http://cgi.di.uoa.gr/~std10108/a.txt");

BufferedReader in = new BufferedReader(

new InputStreamReader(oracle.openStream()));

PrintWriter writer = new PrintWriter("the-file-name.txt", "UTF-8");

String inputLine;

while ((inputLine = in.readLine()) != null)

{

writer.write(inputLine+"\n");

System.out.println(inputLine);

}

writer.close();

in.close();

}

}

The ouput at the console is:

This is a message!

This is a second line!

as it should be. The file is exactly this. Whereas the file that is created, contains this:

This is a message!This is a second line!

I cannot understand what I am doing wrong.

EDIT: I tried this but it doesn't works either

writer.write(inputLine + System.getProperty( "line.separator" ));

Yes I open the file with notepad, and I am at windows. I want to take the program to android so any further information would be usefull

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐