精华区 [关闭][返回]

当前位置:网易精华区>>讨论区精华>>编程开发>>● Java>>JAVA编程>>中文问题>>Java中文问题(参考3)

主题:Java中文问题(参考3)
发信人: head()
整理人: hht(1999-03-11 11:09:53), 站内信件
From:
                                                                       12:59
Subject: [中文Q&A]java聊天室的中文问题To: [email protected]

From:      [email protected] via BBS mail gateway
Subject:   [中文Q&A]java聊天室的中文问题
Date:      Tue Jun  9 12:59:40 1998
To:        To

发信人: [email protected] (真想去爬山!!), 信区: Java
标  题: java聊天室的中文问题
发信站: 交大资工凤凰城资讯站 (Tue Apr 14 18:52:12 1998)
转信站: cis_nctu!news.cis.nctu!news.csie.nctu!phoenix
来  源: mis4k.mis.yuntech.edu.tw

请问各位
我最近使用java撰写一个聊天室
不过使用浏览器使用时输入中文时
传出来的讯息是乱码
我玩一些别人的聊天室也是有相同的问题
无法用中文对谈
请问这是java socket的限制吗?
还是有技术可以解决
谢谢您的回答 !!

>==========================================================================<
发信人: [email protected] (哲哲鱼), 信区: Java
标 题: Re: java聊天室的中文问题
发信站: 交大资工凤凰城资讯站 (Tue Apr 14 19:41:16 1998)
转信站: cis_nctu!news.cis.nctu!news.csie.nctu!phoenix
来 源: kimicat.m1.ntu.edu.tw

==> 在 yech@phoenix (真想去爬山!!) 的文章中提到:
: 请问各位
: 我最近使用java撰写一个聊天室
: 不过使用浏览器使用时输入中文时
: 传出来的讯息是乱码
: 我玩一些别人的聊天室也是有相同的问题
: 无法用中文对谈
: 请问这是java socket的限制吗?
: 还是有技术可以解决
: 谢谢您的回答 !!

  换个 Java VM 试试看。
  至少我试过 IE 4.0 是没问题。
  Sun 的 JDK1.1.5 中的 Appletviewer 也没问题。

>==========================================================================<
发信人: [email protected] (卢弟), 信区: Java
标 题: Re: java聊天室的中文问题
发信站: 辅仁大学美少女梦工场 BBS 站 (Wed Apr 15 00:24:59 1998)
转信站: cis_nctu!news.cis.nctu!news.csie.nctu!news.svdcc.fju!fjubbs
来 源: bbs.svdcc.fju.edu.tw

【 在 [email protected] (真想去爬山!!) 的大作中提到: 】
: 请问各位
: 我最近使用java撰写一个聊天室
: 不过使用浏览器使用时输入中文时
: 传出来的讯息是乱码
: 我玩一些别人的聊天室也是有相同的问题
: 无法用中文对谈
: 请问这是java socket的限制吗?
: 还是有技术可以解决
: 谢谢您的回答 !!

  试试 DataOutputStream中的writeUTF() and readUTF(),
  不过要JDK1.1以後的才有效。
  或是自己把Unicode转Ascii

  public static String AsciiToChinsesString(String s) {
    char[] orig = s.toCharArray();
    byte[] dest = new byte[orig.length];
    for (int i=0;i<orig.length;i++)
dest[i] = (byte)(orig[i]&0xFF);
try {
ByteToCharConverter toChar = ByteToCharConverter.getConverter("Big5");
return new String(toChar.convertAll(dest));
}
catch (Exception e) {
System.out.println(e);
return s;
}
}

public static String ChineseStringToAscii(String s) {
try {
CharToByteConverter toByte = CharToByteConverter.getConverter("Big5");
byte[] orig = toByte.convertAll(s.toCharArray());
char[] dest = new char[orig.length];
for (int i=0;i<orig.length;i++)
dest[i] = (char)(orig[i] & 0xFF);
return new String(dest);
}
catch (Exception e) {
System.out.println(e);
return s;
}
}

>==========================================================================<
发信人: [email protected] (真想去爬山!!), 信区: Java
标 题: Re: java聊天室的中文问题
发信站: 交大资工凤凰城资讯站 (Wed Apr 15 15:02:58 1998)
转信站: cis_nctu!news.cis.nctu!news.cs.nthu!news.csie.nctu!phoenix
来 源: mis4k.mis.yuntech.edu.tw

==> 在 pcchen@phoenix (哲哲鱼) 的文章中提到:
: ==> 在 yech@phoenix (真想去爬山!!) 的文章中提到:
: : 请问各位
: : 我最近使用java撰写一个聊天室
: : 不过使用浏览器使用时输入中文时
: : 传出来的讯息是乱码
: : 我玩一些别人的聊天室也是有相同的问题
: : 无法用中文对谈
: : 请问这是java socket的限制吗?
: : 还是有技术可以解决
: : 谢谢您的回答 !!
:   换个 Java VM 试试看。
:   至少我试过 IE 4.0 是没问题。
:   Sun 的 JDK1.1.5 中的 Appletviewer 也没问题。
请问您的资料流传送是用哪一个class
是PrintStream 还是 DataOutputStream,method是用哪一个送出资料 ?
输入是用DataInputStream中的哪一个method ?
谢谢您的问题 !

>==========================================================================<
发信人: [email protected] (哲哲鱼), 信区: Java
标 题: Re: java聊天室的中文问题
发信站: 交大资工凤凰城资讯站 (Wed Apr 15 15:53:12 1998)
转信站: cis_nctu!news.cis.nctu!news.csie.nctu!phoenix
来 源: ntucsv.csie.ntu.edu.tw

==> 在 yech@phoenix (真想去爬山!!) 的文章中提到:
: ==> 在 pcchen@phoenix (哲哲鱼) 的文章中提到:
: :   换个 Java VM 试试看。
: :   至少我试过 IE 4.0 是没问题。
: :   Sun 的 JDK1.1.5 中的 Appletviewer 也没问题。
: 请问您的资料流传送是用哪一个class
: 是PrintStream 还是 DataOutputStream,method是用哪一个送出资料 ?
: 输入是用DataInputStream中的哪一个method ?
: 谢谢您的问题 !

  基本上我是用 object serialization 的方式把一个 object 经由
  ObjectInputStream 和 ObjectOutputStream 传送的……
  在 ObjectInputStream 中有 readObject() 读入 object
  在 ObjectOutputStream 中有 writeObject() 送出 object
  这样子写会有一些额外的 overhead,不过好处是容易写,容易规划
  基本上,有 implements Serializable 的 classes 都可以被 serial 到 stream
  所以你可以直接把 String 拿来 serialize,或是自己写一个讯息 class。

>==========================================================================<
发信人: [email protected] (● Random Play G., 信区: Java
标 题: Re: java聊天室的中文问题
发信站: 中央大学松涛风情资讯站 (Thu Apr 16 09:58:06 1998)
转信站: cis_nctu!news.cis.nctu!news.nctu!news.csie.ncu!Evergreen
来 源: @mbox.ee.ncu.edu.tw

>==>发信人: [email protected] (卢弟), 信区: Java
>【 在 [email protected] (真想去爬山!!) 的大作中提到: 】
>: 无法用中文对谈
>: 请问这是java socket的限制吗?
>  不过要JDK1.1以後的才有效。
>  或是自己把Unicode转Ascii

>  public static String AsciiToChinsesString(String s) {
>    char[] orig = s.toCharArray();
>    byte[] dest = new byte[orig.length];
>    for (int i=0;i<orig.length;i++)
>      dest[i] = (byte)(orig[i]&0xFF);
>    try {
>      ByteToCharConverter toChar = ByteToCharConverter.getConverter("Big5");
       ^^^^^^^^^^^^^^^^^^^
请问一下JAVA本身有提供这样的Class让人用吗?Or这是在其他软体所另外提供的
package里头的。

>==========================================================================<
发信人: "冬烘先生" <[email protected]>, 信区: Java
标  题: Re: java聊天室的中文问题
发信站: home (Thu Apr 16 12:27:06 1998)
转信站: cis_nctu!news.cis.nctu!news.csie.nctu!news.civil.ncku!news.ncku!news
来  源: p18001.ts.ncku.edu.tw

● Random Play G.N. 撰写於文章 <[email protected]>...
>>==>发信人: [email protected] (卢弟), 信区: Java
>>【 在 [email protected] (真想去爬山!!) 的大作中提到: 】
>>: 无法用中文对谈
>>: 请问这是java socket的限制吗?
>>  不过要JDK1.1以後的才有效。
>>  或是自己把Unicode转Ascii

我曾在MSDN中找到类似问题的解法,是将读进来的stream
转成localizedstream(顾名思义可以show出中文)

>==========================================================================<
发信人: [email protected] (9999999999999999, 信区: Java
标 题: Re: java聊天室的中文问题
发信站: 暨大水沙连站 (Thu Apr 16 12:45:07 1998)
转信站: cis_nctu!news.cis.nctu!news.cs.nthu!news.tceb!ccnews.nchu!news.ncnu!wa

※ 引述《[email protected] (● Random Play G.N.)》之铭言:
: >【 在 [email protected] (真想去爬山!!) 的大作中提到: 】
: >  不过要JDK1.1以後的才有效。
: >  或是自己把Unicode转Ascii
: >      ByteToCharConverter toChar = ByteToCharConverter.getConverter("Big5");
:        ^^^^^^^^^^^^^^^^^^^
: 请问一下JAVA本身有提供这样的Class让人用吗?Or这是在其他软体所另外提供的
: package里头的。

Yes... unDocumented
look at source file of JDK, especially under java.io.*

>==========================================================================<
发信人: [email protected] (● Random Play G., 信区: Java
标 题: Re: java聊天室的中文问题
发信站: 中央大学松涛风情资讯站 (Thu Apr 16 20:22:45 1998)
转信站: cis_nctu!news.cis.nctu!news.cs.nthu!news.nthu!newsfeed.nthu!news.nctu!
来 源: @mbox.ee.ncu.edu.tw

>==>发信人: [email protected] (卢弟), 信区: Java
>【 在 [email protected] (真想去爬山!!) 的大作中提到: 】
>: 请问各位
>: 谢谢您的回答 !!
>  试试 DataOutputStream中的writeUTF() and readUTF(),
>  不过要JDK1.1以後的才有效。
>  或是自己把Unicode转Ascii
>  public static String AsciiToChinsesString(String s) {
>    char[] orig = s.toCharArray();
>    }
>  }
>  public static String ChineseStringToAscii(String s) {
>      CharToByteConverter toByte = CharToByteConverter.getConverter("Big5");
>      return s;
>    }
>  }

请问上述这个方法是不是要先在Server端将中文转成Ascii之後,然後client接
收到之後再将ascii转成chinese? 因为目前找不到CharToByteconverter这个
class所以,先上来这边问罗...谢谢回答。

--
☆ 来源:.广州网易BBS站 bbs.nease.net.[FROM: 202.101.127.250]

[关闭][返回]