Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java SE 综合讨论区 » 编程/算法/API  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 实在没折,求救诸位高手关于中文转换问题(已解决)~~~
junsansi





发贴: 30
积分: 0
于 2005-12-19 12:52 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
URL url= new URL(myUrl); //得到文件的URL地址

BufferedReader in= new BufferedReader(new InputStreamReader(url.openStream()));

String line;
StringBuffer content = new StringBuffer(); //文件内容
while ((line = in.readLine()) != null) { //读取文件
content.append(line+"\n");
}
result = content.toString();
我用上述方法,希望取得一个url的内容,对于英文字符没有任何问题,但中文统统读取不出来显示成???,我加了result = new String(result.getBytes("iso-8859-1"));也不管用

大虾帮忙看看这块还应该做什么转换吗~~~


junsansi edited on 2005-12-21 16:54

作者 Re:实在没折,求救诸位高手关于中文转换问题~~~ [Re:junsansi]
junsansi





发贴: 30
积分: 0
于 2005-12-19 13:47 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
为什么为什么为什么没有人解答啊!!!!!!!


作者 Re:实在没折,求救诸位高手关于中文转换问题~~~ [Re:junsansi]
Jcat

熊猫的猫



发贴: 266
积分: 16
于 2005-12-19 17:46 user profilesend a private message to usersend email to Jcatsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
猜想一: getBytes("ISO8859_1");

猜想二: 你的文件存的时候有误吗?



编程,游泳,睡觉--SleepingCat
作者 Re:实在没折,求救诸位高手关于中文转换问题~~~ [Re:junsansi]
beauchen





发贴: 4
积分: 0
于 2005-12-20 17:29 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
不了解 学习中...


作者 Re:实在没折,求救诸位高手关于中文转换问题~~~ [Re:Jcat]
junsansi





发贴: 30
积分: 0
于 2005-12-21 08:49 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
Jcat wrote:
猜想一: getBytes("ISO8859_1");

猜想二: 你的文件存的时候有误吗?

试过iso-8859-1,iso8859-1,gbk,统统无效

文件确保没有问题,因为里面为了测试方便,我就打了几个中文加字母!



作者 Re:实在没折,求救诸位高手关于中文转换问题~~~ [Re:junsansi]
junsansi





发贴: 30
积分: 0
于 2005-12-21 16:54 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我搞定了,多谢大家!


作者 Re:实在没折,求救诸位高手关于中文转换问题(已解决) [Re:junsansi]
why

問題兒童

总版主


发贴: 4629
积分: 388
于 2005-12-21 19:43 user profilesend a private message to usersend email to whysearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
junsansi wrote:
我搞定了,多谢大家!

Please share your experience with us. Thanks.

Anyway, it is nice that you put (已解决) in the subject line of this topic.



作者 Re:实在没折,求救诸位高手关于中文转换问题(已解决)~~~ [Re:junsansi]
junsansi





发贴: 30
积分: 0
于 2005-12-22 10:38 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
actually,it's really simplay~~
but im not take it early~

just set “BufferedReader in= new BufferedReader(new InputStreamReader(url.openStream()));” as
“BufferedReader in= new BufferedReader(new InputStreamReader(url.openStream(),"iso-8859-1"));”



作者 Re:实在没折,求救诸位高手关于中文转换问题(已解决)~~~ [Re:junsansi]
junsansi





发贴: 30
积分: 0
于 2005-12-22 10:39 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
by the way,i have another question:

http://www.cjsdn.net/post/view?bid=51&id=166043&sty=1&tpg=1&age=30

needs help~~



作者 Re:实在没折,求救诸位高手关于中文转换问题(已解决)~~~ [Re:junsansi]
acl2005





发贴: 54
积分: 0
于 2005-12-24 23:58 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
请你有时间把解决过程给我们写一下好吗??
想向你学习一下!!!谢谢



作者 Re:实在没折,求救诸位高手关于中文转换问题(已解决)~~~ [Re:junsansi]
ljkuan





发贴: 1
积分: 0
于 2005-12-25 14:39 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
试试看:
result = new String(result.getBytes("gb2312"),"ISO8859_1"));



作者 Re:实在没折,求救诸位高手关于中文转换问题(已解决)~~~ [Re:junsansi]
sanigo

给我三刀吧

版主


发贴: 529
积分: 395
于 2005-12-26 01:27 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
你知道吗?
关键是new InputStreamReader(url.openStream())
如果文件是以GBK编码存的,那么应该new InputStreamReader(url.openStream(),"GBK")
那么才能从原理上保证不丢字符信息,即读取出来的是正确的字符(Java内部是Unicode)

相信我,没错的



明天的明天的明天的明天
作者 Re:实在没折,求救诸位高手关于中文转换问题(已解决)~~~ [Re:sanigo]
junsansi





发贴: 30
积分: 0
于 2005-12-26 09:25 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
sanigo wrote:
你知道吗?
关键是new InputStreamReader(url.openStream())
如果文件是以GBK编码存的,那么应该new InputStreamReader(url.openStream(),"GBK")
那么才能从原理上保证不丢字符信息,即读取出来的是正确的字符(Java内部是Unicode)

相信我,没错的


没错,是这样,我是百试不得其解的时候,拿jbuilder挨个试方法试出来的~~~
java的api说明不完善,以至于遇到问题想查找说明都不知道去哪查

sanigo老大有什么好的参考资料吗~



作者 Re:实在没折,求救诸位高手关于中文转换问题(已解决)~~~ [Re:junsansi]
sanigo

给我三刀吧

版主


发贴: 529
积分: 395
于 2005-12-26 16:04 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
看Java Language Reference吧。


明天的明天的明天的明天
作者 Re:实在没折,求救诸位高手关于中文转换问题(已解决)~~~ [Re:junsansi]
why

問題兒童

总版主


发贴: 4629
积分: 388
于 2005-12-26 18:47 user profilesend a private message to usersend email to whysearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
junsansi wrote:
没错,是这样,我是百试不得其解的时候,拿jbuilder挨个试方法试出来的~~~
java的api说明不完善,以至于遇到问题想查找说明都不知道去哪查

Question

http://java.sun.com/j2se/1.4.2/docs/api/java/io/InputStreamReader.html#InputStreamReader(java.io.InputStream,%20java.lang.String)

public InputStreamReader(InputStream in, String charsetName)
 throws UnsupportedEncodingException
Create an InputStreamReader that uses the named charset.

雖然Java的API doc不算十分完善,但若閣下知道InputStreamReader,
大概不必"拿jbuilder挨个试方法试出来"吧.



作者 Re:实在没折,求救诸位高手关于中文转换问题(已解决)~~~ [Re:junsansi]
junsansi





发贴: 30
积分: 0
于 2005-12-27 08:59 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
惭愧,我是初学者,有一点asp的基础,之前没接触过java程式,遇到问题之后一般是到google搜索类似的功能,然后再在其基础上改成自己想要的~~

希望能跟大家多学习,多交流,共同提高共同进步~




flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923