<p>Is there a way to change the encoding used by the String(byte[]) constructor ?</p>

<p>In my own code I use String(byte[],String) to specify the encoding but I am using an external library that I cannot change.</p>

<pre><code>String src = "with accents: é à";
byte[] bytes = src.getBytes("UTF-8");
System.out.println("UTF-8 decoded: "+new String(bytes,"UTF-8"));
System.out.println("Default decoded: "+new String(bytes));
</code></pre>

<p>The output for this is :</p>

<pre>UTF-8 decoded: with accents: é à
Default decoded: with accents: Ã© Ã 
</pre>

<p>I have tried changing the system property <code>file.encoding</code> but it does not work.</p>

[{'answer_id': 81363, 'author': 'jrudolph', 'author_id': 7647, 'author_profile': 'https://Stackoverflow.com/users/7647', 'pm_score': 1, 'selected': False, 'text': '<p>Quoted from <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/nio/charset/Charset.html" rel="nofollow noreferrer">defaultCharset()</a></p>\n\n<blockquote>\n  <p>The default charset is determined\n  during virtual-machine startup and\n  typically depends upon the locale and\n  charset of the underlying operating\n  system.</p>\n</blockquote>\n\n<p>In most OSes you can set the charset using a environment variable.</p>\n'}, {'answer_id': 81366, 'author': 'Mat Mannion', 'author_id': 6282, 'author_profile': 'https://Stackoverflow.com/users/6282', 'pm_score': 4, 'selected': True, 'text': '<p>You need to change the locale before launching the JVM; see:</p>\n\n<p><a href="http://bugs.sun.com/bugdatabase/view_bug.do;jsessionid=6f932817e77b249681417c21bfaf?bug_id=4163515" rel="noreferrer">Java, bug ID 4163515</a></p>\n\n<p>Some places seem to imply you can do this by setting the file.encoding variable when launching the JVM, such as </p>\n\n<pre><code>java -Dfile.encoding=UTF-8 ...\n</code></pre>\n\n<p>...but I haven\'t tried this myself. The safest way is to set an environment variable in the operating system.</p>\n'}, {'answer_id': 12761690, 'author': 'iileandro', 'author_id': 1051999, 'author_profile': 'https://Stackoverflow.com/users/1051999', 'pm_score': 1, 'selected': False, 'text': '<p>I think you want this: System.setProperty("file.encoding", "UTF-8");</p>\n\n<p>It solved some problems, but I still have another ones. The chars "í" and "Í" doesn\'t convert correctly if the SO is ISO-8859-1. Just with the JVM option on startup, I get it solved. Now just my Java Console in  the NetBeans IDE is crashing charset when showing special chars.</p>\n'}]
['https://Stackoverflow.com/questions/81323', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/7198/']