String(byte[] bytes, String charsetName) constructor from String has the following syntax.
public String(byte[] bytes, String charsetName) throws UnsupportedEncodingException
In the following code shows how to use String.String(byte[] bytes, String charsetName) constructor.
import java.io.UnsupportedEncodingException; /* w ww . j a va2 s.co m*/ public class Main { public static void main(String[] argv) { byte[] bytes = new byte[]{65,66,67,68}; try { System.out.println(new String(bytes,"ASCII")); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
The code above generates the following result.