您好,关于java string 的charsetname的具体问题如下:

public class NewClass {
public static void main(String[] args)
{
byte[] b={1,2,3};
String str = new String(b,2,3,UTF-16);
System.out.println(str);
}
}
//sdk java1.6 , 为什麼error
//Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - 找不到符号
符号: 变量 UTF

红糖糍粑
浏览 303回答 2
2回答

慕侠2389804

先加import java.nio.charset.Charset;String str = new String(b,2,3,UTF-16);改为String str = new String(b,2,3,Charset.forName("UTF-16"));这个地方需要的是Charset类...

梦里花落0921

public class NewClass {public static void main(String[] args){byte[] b={1,2,3};String str = new String(b,2,3,UTF-16) // 这里会下标越界;System.out.println(str);}}把这段代码改成:import java.io.*;public class NewClass {public static void main(String[] args){try{byte[] b={1,2,3};String str = new String(b,1,2,"UTF-16");// 这里会抛出一个i里的异常System.out.println(str);}catch(UnsupportedEncodingException e){e.printStackTrace();}}}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java
JQuery