default encoding of a jvm

J

Joseph Millar

how can i get the default encoding value of a jvm or a system?

System.getProperty("file.encoding");

On my XP system, it yields "Cp1252", on my Linux box it's "UTF-8".
Based on your language and region, you will get different values
(maybe).

--Joe
 
X

X_AWieminer_X

how can i get the default encoding value of a jvm or a system?

This little trick should tell you the JVM-OS default encoding. More
transparent implementation would use a os-generated temporary file and
then delete it. Most likely utility class with a static value would
create a temp file on first method invocation and then reuse that value.

I dont know whether we could use FileReader to achieve the same encoding
value.

private String getDefaultCharSet() throws IOException {
FileWriter filewriter = new FileWriter("out");
String encname = filewriter.getEncoding();
filewriter.close();
return encname;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top