百度
360搜索
搜狗搜索

javaunicode转中文,java maven pom properties配置unicode编码怎么变成了中文不让目标文件显示中文详细介绍

本文目录一览: 找一个能将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编码的文件内容,并转换成汉字?

public static void main(String[] args) throws IOException {
String path = "E:/a.txt";
File file = null;
BufferedReader br = null;
file = new File(path);
br = new BufferedReader(new InputStreamReader(
new FileInputStream(file), "gbk"));
StringBuilder sb = new StringBuilder();
String length = "";
while ((length = br.readLine()) != null) {
sb.append(length);
}
System.out.println(ascii2Native(sb.toString()));

}
//unicode转为本地
public static String ascii2Native(String str) {
StringBuilder sb = new StringBuilder();
int begin = 0;
int index = str.indexOf("\\u");
while (index != -1) {
sb.append(str.substring(begin, index));
sb.append(ascii2Char(str.substring(index, index + 6)));
begin = index + 6;
index = str.indexOf("\\u", begin);
}
sb.append(str.substring(begin));
return sb.toString();
}
private static char ascii2Char(String str) {
if (str.length() != 6) {
throw new IllegalArgumentException(
"Ascii string of a native character must be 6 character.");
}
if (!"\\u".equals(str.substring(0, 2))) {
throw new IllegalArgumentException(
"Ascii string of a native character must start with \"\\u\".");
}
String tmp = str.substring(2, 4);
int code = Integer.parseInt(tmp, 16) << 8;
tmp = str.substring(4, 6);
code += Integer.parseInt(tmp, 16);
return (char) code;
}
}
逐个字符读,遇到\u取后面4个字符,转换成byte[] byte4s、再转换成new String(byte4s, "utf-8");第二个参数随你文件中真正的字符集而改变。
可以通过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 转成中文!

public class Convert{ private static String ascii2native ( String asciicode ) { String[] asciis = asciicode.split ("\\\\u"); String nativeValue = asciis[0]; try { for ( int i = 1; i < asciis.length; i++ ) { String code = asciis[i]; nativeValue += (char) Integer.parseInt (code.substring (0, 4), 16); if (code.length () > 4) { nativeValue += code.substring (4, code.length ()); } } } catch (NumberFormatException e) { return asciicode; } return nativeValue; } public static void main ( String[] args ) { String str = "\"JWHQK_JWQC\":\"\u6c5f\u5b89\u793e\u533a\u5c45\u6c11\u59d4\u5458\u4f1a\""; String result = ascii2native (str); System.out.println(result); }}

阅读更多 >>>  win7模拟器怎么调中文

如何把properties中的所有unicode编码转为汉字

在命令行界面用native2ascii工具
1.将汉字转为Unicode:
C:\Program Files\Java\jdk1.5.0_04\bin>native2ascii
测试
\u6d4b\u8bd5
2.将Unicode转换为汉字:
C:\Program Files\Java\jdk1.5.0_04\bin>native2ascii -reverse
\u6d4b\u8bd5
测试
java 自带的一个native2ascii.exe是一个很好的转码工具,在bin目录下。如果你的properties中有汉字,需要转成unicode . 则把含有汉字的properties拷贝到bin 目录下, 然后在cmd里面进入bin目录,输入:native2ascii -encoding utf-8 Language-ext_zh_CN.properties.native Language-ext_zh_CN.properties就ok了。Language-ext_zh_CN.properties是转码后的文件。
在做Java开发的时候,常常会出现一些乱码,或者无法正确识别或读取的文件,比如常见的validator验 证用的消息资源(properties)文件就需要进行Unicode重新编码。原因是java默认的编码方式为Unicode,而我们的计算机系统编码 常常是GBK等编码。需要将系统的编码转换为java正确识别的编码问题就解决了。
1、native2ascii简介:native2ascii 是sun java sdk提供的一个工具。用来将别的文本类文件(比如*.txt,*.ini,*.properties,*.java等等)编码转为Unicode编码。 为什么要进行转码,原因在于程序的国际化。Unicode编码的定义:Unicode(统一码、万国码、单一码)是一种在计算机上使用的字符编码。它为每 种语言中的每个字符设定了统一并且唯一的二进制编码,以满足跨语言、跨平台进行文本转换、处理的要求。1990年开始研发,1994年正式公布。随着计算 机工作能力的增强,Unicode也在面世以来的十多年里得到普及。(声明:Unicode编码定义来自互联网)。
2、获取native2ascii:安装了jdk后,假如你是在windows上安装,那么在jdk的安装目录下,会有一个bin目录,其中native2ascii.exe正是。
3、native2ascii的命令行的命名格式:
native2ascii -[options] [inputfile [outputfile]]
说明:
-[options]:表示命令开关,有两个选项可供选择
-reverse:将Unicode编码转为本地或者指定编码,不指定编码情况下,将转为本地编码。
-encoding encoding_name:转换为指定编码,encoding_name为编码名称。
[inputfile [outputfile]]
inputfile:表示输入文件全名。
outputfile:输出文件名。如果缺少此参数,将输出到控制台。
4、最佳实践:首先将JDK的bin目录加入系统变量path。在盘下建立一个test目录,在test目录里建立一个zh.txt文件,文件内容为:“熔岩”,打开“命令行提示符”,并进入C:\test目录下。下面就可以按照说明一步一步来操作,注意观察其中编码的变化。
A:将zh.txt转换为Unicode编码,输出文件到u.txt
native2ascii zh.txt u.txt
打开u.txt,内容为“\u7194\u5ca9”。
B:将zh.txt转换为Unicode编码,输出到控制台
C:\test>native2ascii zh.txt
\u7194\u5ca9
可以看到,控制台输出了“\u7194\u5ca9”。
C:将zh.txt转换为ISO8859-1编码,输出文件到i.txt
native2ascii -encoding ISO8859-1 zh.txt i.txt
打开i.txt文件,内容为“\u00c8\u00db\u00d1\u00d2”。
D:将u.txt转换为本地编码,输出到文件u_nv.txt
native2ascii -reverse u.txt u_nv.txt
打开u_nv.txt文件,内容为“熔岩”。
E:将u.txt转换为本地编码,输出到控制台
C:\test>native2ascii -reverse u.txt
熔岩
可以看到,控制台输出了“熔岩”。
F:将i.txt转换为本地编码,输出到i_nv.txt
native2ascii -reverse i.txt i_nv.txt
打开i_nv.txt文件,内容为“\u00c8\u00db\u00d1\u00d2”。发现转码前后完全一样的。也就是说,等于没有转,或者说思想糊涂,对命名没有理解。。
G:将i.txt转换为GBK编码,输出到i_gbk.txt
native2ascii -reverse -encoding GBK i.txt i_gbk.txt
打开i_gbk.txt文件,内容为“\u00c8\u00db\u00d1\u00d2”。发现转码前后完全一样的。也就是说,等于没有转,或者说思想糊涂,对命名没有理解。
H:将u_nv.txt转码到本地编码GBK,输出到控制台
C:\test>native2ascii -reverse -encoding ISO8859-1 i.txt
熔岩
从这个结果看,目标达到到了,编码i.txt为ISO8859-1,转为本地编码后内容为“熔岩”。从这里应该意识到,native2ascii -reverse命令中-encoding指定的编码为源文件的编码格式。而在native2ascii 命令中-encoding指定的编码为(生成的)目标文件的编码格式。这一点非常的重要!切记!!
继续探索,新建文件12a.txt,内容“12axyz”。看看纯字母数字的编码又如何。
I:将纯字母数字的文本文件12a.txt转换为Unicode编码
native2ascii 12a.txt 12a_nv.txt
打开12a_nv.txt文件,内容为“12axyz”。
继续测试,转为ISO8859-1编码看看
C:\test>native2ascii -encoding ISO8859-1 12a.txt
12axyz
结果还是没有转码。
从结果可以得出结论:对于纯数字和字母的文本类型件,转码前后的内容是一样的。

Java使用百度API store返回JSON数据为unicode编码,怎么转化为中文

String str = "\u8eab\u4efd\u8bc1\u53f7\u7801\u4e0d\u5408\u6cd5!";
byte[] bt = str.getBytes("utf-8");
String ret = new String(bt, "utf-8");
System.out.println(ret);

java 中把自己的名字的Unicode编码输出 例如欧=23121 阳=43212,....

Scanner input=new Scanner(System.in); System.out.println("输入你要转换的字符串:"); String str=input.next(); String result=""; for (int i = 0; i < str.length(); i++){ char ch = str.charAt(i); if(ch>=19968&&ch<=171941){ //判断是否为中文(汉字范围 \u4e00-\u9fa5 (中文)) result+=ch+":"+"\\u" + Integer.toHexString(ch)+"\n"; }else{ result+=str.charAt(i); } } System.out.println(result);你的Unicode对应的编码好像是不对的,是乱写的?
先将名字使用split()拆分成数组,再使用 String 的getbytes(),格式使用unicode;转换后再连接成String

java中如何取得中文如“中国”在unicode编码中的表示串

可以这样来重构字符串newString(“XXX".getByte(),”UTF-8“);后面加上编码方式
public class Demo
{
public static void main(String[] args)
{
String str="例子";
//数组bm保存的就是"例子"的Unicode代码点(10进制)
int[] bm=new int[str.length()];

for(int i=0;i
<str.length();i++)
{

bm[i]=str.codePointAt(i);

System.out.print(""+bm[i]+" ");

}

}

}
</str.length();i++)

java maven pom properties配置unicode编码怎么变成了中文不让目标文件显示中文

是否显示中文,和编码无关,和maven过滤器无关,和打开config.properties这个文件使用的文本编辑器是否能够自动识别UTF码有关。配置文本编码格式为UTF-8,文本编辑器用UFT-8标准去解码显示,当然是能够正确显示中文的啊。

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

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

网站数据信息

"javaunicode转中文,java maven pom properties配置unicode编码怎么变成了中文不让目标文件显示中文"浏览人数已经达到20次,如你需要查询该站的相关权重信息,可以点击进入"Chinaz数据" 查询。更多网站价值评估因素如:javaunicode转中文,java maven pom properties配置unicode编码怎么变成了中文不让目标文件显示中文的访问速度、搜索引擎收录以及索引量、用户体验等。 要评估一个站的价值,最主要还是需要根据您自身的需求,如网站IP、PV、跳出率等!