gpt4 book ai didi

java - 在 KOI8_R 中检索 html

转载 作者:行者123 更新时间:2023-12-01 05:42:13 25 4
gpt4 key购买 nike

我想检索一些在 KOI8_R 中编码的 html。如何在不损坏字符的情况下检索它?

import java.io.*;
import java.net.URL;
import java.net.URLConnection;

public class htmlget {

public static void main(String[] args) throws Exception {
String test = "http://koi8.pp.ru/";
URL website = new URL(test);
URLConnection yc = website.openConnection();
StringBuilder fileData = new StringBuilder(1000);
BufferedReader in = new BufferedReader(
new InputStreamReader(
yc.getInputStream(),"KOI8_R"));

char[] buf = new char[1024];
int numRead=0;
while((numRead=in.read(buf)) != -1){
fileData.append(buf, 0, numRead);
}
in.close();

String text = fileData.toString();
BufferedWriter out = new BufferedWriter(
new OutputStreamWriter(new FileOutputStream("foo.txt"),"KOI8_R"));
out.write(text);
OutputStreamWriter wrt = new OutputStreamWriter(System.out, "KOI8_R");
wrt.write(text);
wrt.close();
out.close();
}

}

控制台和文件显示俄语字符为“ÓÅÇÏÄÎÑ”

最佳答案

(...)
in.close();

String text = new String(fileData.toString().getBytes(), "KOI8_R");
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream("foo.txt"), "KOI8_R"));
out.write(text);
(...)

关于java - 在 KOI8_R 中检索 html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6824390/

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