Topic: 实在没折,求救诸位高手关于中文转换问题(已解决)~~~ |
Print this page |
1.实在没折,求救诸位高手关于中文转换问题(已解决)~~~ | Copy to clipboard |
Posted by: junsansi Posted on: 2005-12-19 12:52 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"));也不管用 大虾帮忙看看这块还应该做什么转换吗~~~ |
2.Re:实在没折,求救诸位高手关于中文转换问题~~~ [Re: junsansi] | Copy to clipboard |
Posted by: junsansi Posted on: 2005-12-19 13:47 为什么为什么为什么没有人解答啊!!!!!!! |
3.Re:实在没折,求救诸位高手关于中文转换问题~~~ [Re: junsansi] | Copy to clipboard |
Posted by: Jcat Posted on: 2005-12-19 17:46 猜想一: getBytes("ISO8859_1"); 猜想二: 你的文件存的时候有误吗? |
4.Re:实在没折,求救诸位高手关于中文转换问题~~~ [Re: junsansi] | Copy to clipboard |
Posted by: beauchen Posted on: 2005-12-20 17:29 不了解 学习中... |
5.Re:实在没折,求救诸位高手关于中文转换问题~~~ [Re: Jcat] | Copy to clipboard |
Posted by: junsansi Posted on: 2005-12-21 08:49 Jcat wrote: 试过iso-8859-1,iso8859-1,gbk,统统无效 文件确保没有问题,因为里面为了测试方便,我就打了几个中文加字母! |
6.Re:实在没折,求救诸位高手关于中文转换问题~~~ [Re: junsansi] | Copy to clipboard |
Posted by: junsansi Posted on: 2005-12-21 16:54 我搞定了,多谢大家! |
7.Re:实在没折,求救诸位高手关于中文转换问题(已解决) [Re: junsansi] | Copy to clipboard |
Posted by: why Posted on: 2005-12-21 19:43 junsansi wrote: Please share your experience with us. Thanks. Anyway, it is nice that you put (已解决) in the subject line of this topic. |
8.Re:实在没折,求救诸位高手关于中文转换问题(已解决)~~~ [Re: junsansi] | Copy to clipboard |
Posted by: junsansi Posted on: 2005-12-22 10:38 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"));” |
9.Re:实在没折,求救诸位高手关于中文转换问题(已解决)~~~ [Re: junsansi] | Copy to clipboard |
Posted by: junsansi Posted on: 2005-12-22 10:39 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~~ |
10.Re:实在没折,求救诸位高手关于中文转换问题(已解决)~~~ [Re: junsansi] | Copy to clipboard |
Posted by: acl2005 Posted on: 2005-12-24 23:58 请你有时间把解决过程给我们写一下好吗?? 想向你学习一下!!!谢谢 |
11.Re:实在没折,求救诸位高手关于中文转换问题(已解决)~~~ [Re: junsansi] | Copy to clipboard |
Posted by: ljkuan Posted on: 2005-12-25 14:39 试试看: result = new String(result.getBytes("gb2312"),"ISO8859_1")); |
12.Re:实在没折,求救诸位高手关于中文转换问题(已解决)~~~ [Re: junsansi] | Copy to clipboard |
Posted by: sanigo Posted on: 2005-12-26 01:27 你知道吗? 关键是new InputStreamReader(url.openStream()) 如果文件是以GBK编码存的,那么应该new InputStreamReader(url.openStream(),"GBK") 那么才能从原理上保证不丢字符信息,即读取出来的是正确的字符(Java内部是Unicode) 相信我,没错的 |
13.Re:实在没折,求救诸位高手关于中文转换问题(已解决)~~~ [Re: sanigo] | Copy to clipboard |
Posted by: junsansi Posted on: 2005-12-26 09:25 sanigo wrote: 没错,是这样,我是百试不得其解的时候,拿jbuilder挨个试方法试出来的~~~ java的api说明不完善,以至于遇到问题想查找说明都不知道去哪查 sanigo老大有什么好的参考资料吗~ |
14.Re:实在没折,求救诸位高手关于中文转换问题(已解决)~~~ [Re: junsansi] | Copy to clipboard |
Posted by: sanigo Posted on: 2005-12-26 16:04 看Java Language Reference吧。 |
15.Re:实在没折,求救诸位高手关于中文转换问题(已解决)~~~ [Re: junsansi] | Copy to clipboard |
Posted by: why Posted on: 2005-12-26 18:47 junsansi wrote: 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挨个试方法试出来"吧. |
16.Re:实在没折,求救诸位高手关于中文转换问题(已解决)~~~ [Re: junsansi] | Copy to clipboard |
Posted by: junsansi Posted on: 2005-12-27 08:59 惭愧,我是初学者,有一点asp的基础,之前没接触过java程式,遇到问题之后一般是到google搜索类似的功能,然后再在其基础上改成自己想要的~~ 希望能跟大家多学习,多交流,共同提高共同进步~ |
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 |