Add to Google Reader or Homepage

java.io.UnsupportedEncodingException

UnsupportedEncodingException:


"An UnsupportedEncodingException will be thrown only if the given Charset is not Supported by your JVM".

There are some particular set of "Charsets"  that are supported by your JVM. If the given charset is not in that list then it is certain that this error will be thrown.

So first check whether the given Charset is supported by your JVM.If you have no idea about the available character sets, Use the following code to list the available charsets.


Map csets = Charset.availableCharsets();
for (String name : csets.keySet())
   System.out.println(name);

See the following program which i have simulated,that causes this error.

Program:

import java.io.*;
import java.util.*;
import java.nio.charset.*;
class Unsuppencode
{
public static void main(String args[])throws Exception
{
ByteArrayOutputStream byteout=new ByteArrayOutputStream(10);
byteout.write(10);
String s=byteout.toString("IBM859");
Map csets = Charset.availableCharsets();
for (String name : csets.keySet())
   System.out.println(name);

}
}


As you see there is no such charset named IBM859 in the JVM thus causing this unsupported encoding exception.So when using a particular charset check whether it is supported(available) by your JVM.

1 comments:

vfshibi said...

Nice article,i like Your site.
Politics news in tamilnadu | politics news chennai | politics news chennai | latest news in tamil

Post a Comment

 
java errors and exceptions © 2010 | Designed by Chica Blogger | Back to top