gpt4 book ai didi

java - URL.getContent 编码错误

转载 作者:太空宇宙 更新时间:2023-11-04 04:19:44 24 4
gpt4 key购买 nike

我有一个 URL,正在尝试写入 Linux 机器上的文件。
我可以做一个

      wget http://localhost/fileIwant.text  

一切都很好。

当我尝试像这样使用 Java 的 URL 时:

    URL url = new URL("http://localhost/fileIwant.text");
URLConnection conn = url.openConnection();
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));

String inputLine;
File file = new File(path+filename);

if (!file.exists()) {
file.createNewFile();
}

//use FileWriter to write file
FileWriter fw = new FileWriter(file.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);

while ((inputLine = br.readLine()) != null) {
bw.write(inputLine);
}

我已经尝试了我能想到的所有读取器、流、字节[] 的排列,但我仍然得到一个包含钻石的文件?在他们之中。

有什么想法吗?

最佳答案

InputStream in=(new URL("http://localhost/fileIwant.text")).openStream();

关于java - URL.getContent 编码错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14263120/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com