0

I am trying the below code :-

private Charset charset = Charset.forName("UTF-8");
String decryptedtext = new String(decryptedValue, charset);

where decryptedValue is of type byte[] but the above code is not working for java 1.5 version. I am getting the error as below :-

> ERROR: symbol : constructor String(byte[],java.nio.charset.Charset)
> ERROR: location: class java.lang.String
> ERROR: String decryptedtext = new String(decryptedValue, charset); 
> ERROR: ^

Can anyone help me on this ?

Apologies in advance if this is a repetitive or duplicate question.

8
  • 8
    That constructor was added in Java 1.6 Commented Jul 4, 2017 at 5:48
  • 2
    docs.oracle.com/javase/8/docs/api/java/lang/… Commented Jul 4, 2017 at 5:48
  • You should not use such an old java version. It is outdated since many years Commented Jul 4, 2017 at 5:56
  • Here is the Java 5 docs for String: docs.oracle.com/javase/1.5.0/docs/api/java/lang/String.html Commented Jul 4, 2017 at 6:18
  • @Jens The application is based on Java 1.5 and have not migrated to the latest java release Commented Jul 4, 2017 at 9:31

1 Answer 1

1

There is no String(byte[], Charset) constructor in Java 5. You can only use String(byte[], String). Then your code should look like:

String s = new String(decryptedValue, "UTF-8");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.