导航:首页 > 编程语言 > javaunicode转中文

javaunicode转中文

发布时间:2022-06-08 19:45:37

java读取含有unicode编码的文件内容,并转换成汉字

可以通过BufferedReader 流的形式进行流缓存,之后通过readLine方法获取到缓存的内容。

BufferedReader bre = null;
try {
String file = "D:/test/test.txt";
bre = new BufferedReader(new FileReader(file));//此时获取到的bre就是整个文件的缓存流
while ((str = bre.readLine())!= null) // 判断最后一行不存在,为空结束循环
{
System.out.println(str);//原样输出读到的内容(unicode会自动转换为中文的)
};
备注:unicode不需要转换的,直接输出即可,会自动变成中文,如:
System.out.println("\u0061\u0062\u6c49\u5b57");
结果就是:ab汉字。

② 找一个能将JAVA代码中Unicode编码为字符集转换为汉字的小软件

利用JDK中自带的native2ascii工具就很好

如果是在项目中,可以直接拷贝%JDK%/bin下native2ascii.exe至项目根目录,然后类中这样调用即可
中文转UNICODE(srcFileName为中文文件路径)
StringBuffer tempSb = new StringBuffer();
Process p = Runtime.getRuntime().exec(
"native2ascii "+srcFileName);
InputStreamReader child_in = new InputStreamReader(p
.getInputStream());
int c;
while ((c = child_in.read()) != -1) {
tempSb.append((char) c);
}
System.out.println(tempSb);

UNICODE转中文(srcFileName为UNICODE文件路径)
StringBuffer tempSb = new StringBuffer();
Process p = Runtime.getRuntime().exec(
"native2ascii -reverse "+srcFileName);
InputStreamReader child_in = new InputStreamReader(p
.getInputStream());
int c;
while ((c = child_in.read()) != -1) {
tempSb.append((char) c);
}
System.out.println(tempSb);

③ java如何把以unicode编码形式的字符串变成编码前的形式

不用转,直接输出结果即可,系统会自动转换。举例:

System.out.println("u0061u0062u6c49u5b57");

结果就是:ab汉字。

④ java把unicode还原成汉字

这个本来就是unicode的,按unicode的来读才行。
FF FE 开头是unicode的标志

public class ReadUnicode {
public static void main(String[] args) throws Exception{
String encoding = "Unicode";
String txtFilePath = "ReadUnicode321.txt";//
String tmpLineVal;
InputStreamReader read = new InputStreamReader(new FileInputStream(txtFilePath), encoding);
BufferedReader bufread = new BufferedReader(read);
while((tmpLineVal = bufread.readLine())!=null){
System.out.println(tmpLineVal);
}
bufread.close();
read.close();
}
}

⑤ java 将字符串中含有unicode 转成中文!

publicclassConvert
{
(Stringasciicode)
{
String[]asciis=asciicode.split("\\u");
StringnativeValue=asciis[0];
try
{
for(inti=1;i<asciis.length;i++)
{
Stringcode=asciis[i];
nativeValue+=(char)Integer.parseInt(code.substring(0,4),16);
if(code.length()>4)
{
nativeValue+=code.substring(4,code.length());
}
}
}
catch(NumberFormatExceptione)
{
returnasciicode;
}
returnnativeValue;
}

publicstaticvoidmain(String[]args)
{
Stringstr=""JWHQK_JWQC":""";
Stringresult=ascii2native(str);
System.out.println(result);
}
}

⑥ java中如何在中文字符和unicode编码之间进行转换

可以这样来重构字符串new String(“XXX".getByte(),”UTF-8“);后面加上编码方式

⑦ 用java如何把unicode码转成汉字

java中将unicode码转换成汉字的方式是直接使用string类型,打印即可:

Stringascii="u4f01u4e1a";//这两个unicode码就是企业的
System.out.println(ascii);//打印出来

运行结果:

企业

Unicode只有一个字符集,中、日、韩的三种文字占用了Unicode中0x3000到0x9FFF的部分 Unicode目前普遍采用的是UCS-2,它用两个字节来编码一个字符, 比如汉字"经"的编码是0x7ECF,注意字符编码一般用十六进制来 表示,为了与十进制区分,十六进制以0x开头,0x7ECF转换成十进制 就是32463,UCS-2用两个字节来编码字符,两个字节就是16位二进制, 2的16次方等于65536,所以UCS-2最多能编码65536个字符。

⑧ java 中如何将unicode字符集转换成汉字

我这eclipse自动把它转中文了。。你看下这个。
http://blog.csdn.net/shigang_xing/article/details/8263728

⑨ 用java如何把unicode码转成汉字

Java中字符和字符串都采用的是Unicode编码;汉字能够直接表示;不需要转换
可以测试一下
public
class
Unicode
2Ch
z
{
public
static
void
main(String[]
args)
{
System.out.print(cc);}}直接输出:保

⑩ 如何利用java把文件中的Unicode字符转换为汉字

Java中字符和字符串都采用的是Unicode编码;汉字能够直接表示;不需要转换 可以测试一下public class Unicode2Chz {
public static void main(String[] args) {
String cc="\u4fdd";
System.out.print(cc);
}} 直接输出:保

阅读全文

与javaunicode转中文相关的资料

热点内容
数据库查询系统源码 浏览:617
php5314 浏览:357
完美国际安装到哪个文件夹 浏览:668
什么app可以扫一扫做题 浏览:538
程序员编码论坛 浏览:923
淘点是什么app 浏览:659
中国高等植物pdf 浏览:453
51单片机时间 浏览:182
后台如何获取服务器ip 浏览:267
单片机流水灯程序c语言 浏览:234
程序员第二职业挣钱 浏览:238
运行里怎么输入服务器路径 浏览:840
pythonstepwise 浏览:509
刘一男词汇速记指南pdf 浏览:64
php认证级别 浏览:368
方舟编译啥时候推送 浏览:1011
php手机验证码生成 浏览:675
哲学思维pdf 浏览:14
凌达压缩机有限公司招聘 浏览:534
weblogic命令部署 浏览:37