从网页提存文字的乱码问题
时间: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) {}
}
}
以下是把英文字 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 编辑 ] 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-03-30
form5, 谢谢你的程式
作者: threemonth 发布时间: 2014-03-30
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28