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
In the following code shows how to use String.String(byte[] bytes, int offset, int length, String charsetName) constructor.
// w ww . j a v a 2s . c o m 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.