【发布时间】:2016-10-24 14:32:12
【问题描述】:
我想从网站下载一个 .txt 文件,并且我的代码有效,所以我没有收到错误,它会加载文档,但文档中充满了 hmtl 代码,而不是我的内容。
public static void main(String[] args) {
try {
URL website = new URL("http://www.file-upload.net/download-11700212/document.txt.html");
String filepath = "C://Users//" + System.getProperty("user.name") + "//Desktop//document.txt";
ReadableByteChannel channel = Channels.newChannel(website.openStream());
FileOutputStream stream = new FileOutputStream(filepath);
stream.getChannel().transferFrom(channel, 0, Long.MAX_VALUE);
System.out.println("Download successfull.");
} catch (Exception e) {
System.out.println("Download was not successfull.");
}
}
下载本身可以,我在我的桌面上得到了txt文件,但是内容错误并且充满了html代码。
请帮忙。
谢谢。
【问题讨论】:
标签: java file url download web