+ -
当前位置:首页 → 问答吧 → 从网页提存文字的乱码问题

从网页提存文字的乱码问题

时间:2014-03-30

来源:互联网

我想把oxford website 里的英文拼音提取出来,
以下是把英文字 a 的 web page 储存到outputfile.htm的程式,
但那 a 字的拼音变咗乱码其余的文字无问题,
拼音是用一些特别字符的,
究竟是 getContent() 出了问题或是它其问题,
谢谢指教。

import java.io.FileOutputStream;
import java.io.File;

public class Main {
public static void main(String[] args) {
HttpRequester request = new HttpRequester();
try {
HttpRespons hr = request.sendPost("http://oald8.oxfordlearnersdictionaries.com/dictionary/a_4");
FileOutputStream fos = new FileOutputStream(new File("outputfile.htm"));
fos.write(hr.getContent().getBytes());
fos.close();
} catch (Exception e) {}
}
}

作者: threemonth   发布时间: 2014-03-30

复制内容到剪贴板代码:import java.net.*;
import java.io.*;

public class Main {
public static void main(String[] args) throws Exception {
URL oxfordDictionary = new URL("http://oald8.oxfordlearnersdictionaries.com/dictionary/a_4");
URLConnection connection = oxfordDictionary.openConnection();

InputStream in = connection.getInputStream();
FileOutputStream fos = new FileOutputStream(new File("outputfile.htm"));
byte[] buf = new byte[512];
while (true) {
int len = in.read(buf);
if (len == -1) {
break;
}
fos.write(buf, 0, len);
}
in.close();
fos.flush();
fos.close();
}
}
[ 本帖最后由 form5 於 2014-2-25 09:56 PM 编辑 ]

作者: form5   发布时间: 2014-03-30

form5, 谢谢你的程式

作者: threemonth   发布时间: 2014-03-30