求教url.openStream();流的汉字显示问题???

s1234567 2002-12-24 01:28:56
我在APPLET中使用如下URL流代码:

try {
URL url = new URL(getDocumentBase(),
jTextField1.getText());
InputStream is = url.openStream();
//FileInputStream is = new FileInputStream("c:/io/Simon.txt");
DataInputStream in = new DataInputStream(new

BufferedInputStream(is));
String str = new String();
String s = new String();
String line = new String();
byte[] data = new byte[500];
int nbyte;
while ((nbyte = in.read(data))!=-1){
str += new String(data,0,nbyte);
}
in.close();
jTextArea1.append(str);
} catch(Exception ex)

===============
问题: 上面的url.openStream()
产生的输入流只能在TEXTAREA里正确显示英文,
无法显示中文, 究竟是什么原因?
而我直接用文件输入流替代,
却是可以正确显示文件Simon.txt中的中文的.
...全文
107 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧