Java String(byte[] bytes, int offset, int length, String charsetName) Constructor
Syntax
String(byte[] bytes, int offset, int length, String charsetName) constructor from String has the following syntax.
public String(byte[] bytes, int offset, int length, String charsetName) throws UnsupportedEncodingException
Example
In the following code shows how to use String.String(byte[] bytes, int offset, int length, String charsetName) constructor.
//from w w w.j ava2 s . com
import java.io.UnsupportedEncodingException;
public class Main {
public static void main(String[] argv) {
byte[] bytes = new byte[]{65,66,67,68};
try {
System.out.println(new String(bytes,1,3,"ASCII"));
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
The code above generates the following result.