java url to file_Java通过从url读取来创建文件(Java creating file by reading from url)

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值