please use your head public class TestClass { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub String s = "\u4eca\u5929\u767d\u5929\u5230\u591c\u95f4\uff1a"; char[] c = s.toCharArray(); for (int i = 0; i < c.length; i++) { System.out.println(c[i]); } }}
public void EncodeingTest(){
BufferedReader bufread;
String read, readStr = "";
String[] weatherInfo = new String[6];
int i=0;
try {
File file = new File("D:\\weather.info");
FileReader fileread = new FileReader(file);
bufread = new BufferedReader(fileread);
while ((read = bufread.readLine()) != null) {
// System.out.println(read);
weatherInfo[i] = read;
// weatherInfo[i] = new String(read.getBytes(),"unicode");
// weatherInfo[i] = new String(read.getBytes("UTF-8"));
// weatherInfo[i] = new String(read.getBytes("UTF-8"),"unicode");
// weatherInfo[i] = new String(read.getBytes("unicode"),"UTF-8");
System.out.println("weatherInfo["+i+"]= "+weatherInfo[i]);
i++;
}
} catch (Exception d) {
System.out.println(d.getMessage());
}
}
weatherInfo[i] = new String(read.getBytes("UTF-8"),"GBK");楼上的方法试了,不行~~~
public class TestClass { /**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
char[] codes = { '\u4eca', '\u5929', '\u767d', '\u5929', '\u5230',
'\u591c', '\u95f4', '\uff1a' };
for (int i = 0; i < codes.length; i++) {
System.out.println(codes[i]);
} }}
'\u591c', '\u95f4', '\uff1a' };
文本可能是比较长的 !
public class TestClass { /**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String s = "\u4eca\u5929\u767d\u5929\u5230\u591c\u95f4\uff1a";
char[] c = s.toCharArray();
for (int i = 0; i < c.length; i++) {
System.out.println(c[i]);
}
}}
String s = "\\u4e2d\\u56fd"; StringBuffer sb = new StringBuffer();
Pattern p = Pattern.compile("(?i)\\\\u([\\da-f]{4})");
Matcher m = p.matcher(s);
while(m.find()) {
m.appendReplacement(sb, Character.toString((char)Integer.parseInt(m.group(1), 16)));
}
m.appendTail(sb); s = sb.toString();
System.out.println(s);
public static void main(String[] args) {
String str ="23";
transaction(str); }
public static String transaction(String str) {
String s = "";
try {
s = new String(str.getBytes("UTF-8"),"GBK");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return s;
}}