Difference between revisions of "Character encoding"
(New page: Character encoding levert bij de uitwisseling tussen verschillende systemen problemen op. Linux, AIX en Sun Solaris gedragen zich anders. = checks 1 = So if I compile this, we can check. <...) |
(→checks 1) |
||
Line 3: | Line 3: | ||
So if I compile this, we can check. |
So if I compile this, we can check. |
||
<pre> |
<pre> |
||
+ | public class CharSetTest |
||
− | public class CharSetTest { public static void main(String[] args) { System.out.println("Default Charset=" + Charset.defaultCharset()); System.setProperty("file.encoding", "Latin-1"); System.out.println("file.encoding=" + System.getProperty("file.encoding")); System.out.println("Default Charset=" + Charset.defaultCharset()); System.out.println("Default Charset in Use=" + getDefaultCharSet()); } private static String getDefaultCharSet() { OutputStreamWriter writer = new OutputStreamWriter(new ByteArrayOutputStream()); String enc = writer.getEncoding(); return enc; } } |
||
+ | { public static void main(String[] args) |
||
+ | { System.out.println("Default Charset=" + Charset.defaultCharset()); |
||
+ | System.setProperty("file.encoding", "Latin-1"); |
||
+ | System.out.println("file.encoding=" + System.getProperty("file.encoding")); |
||
+ | System.out.println("Default Charset=" + Charset.defaultCharset()); |
||
+ | System.out.println("Default Charset in Use=" + getDefaultCharSet()); } |
||
+ | private static String getDefaultCharSet() |
||
+ | { OutputStreamWriter writer = new OutputStreamWriter(new ByteArrayOutputStream()); |
||
+ | String enc = writer.getEncoding(); |
||
+ | return enc; } } |
||
</pre> |
</pre> |
||
+ | |||
= check 2 = |
= check 2 = |
||
<pre> |
<pre> |
Revision as of 16:31, 23 October 2012
Character encoding levert bij de uitwisseling tussen verschillende systemen problemen op. Linux, AIX en Sun Solaris gedragen zich anders.
Contents
checks 1
So if I compile this, we can check.
public class CharSetTest { public static void main(String[] args) { System.out.println("Default Charset=" + Charset.defaultCharset()); System.setProperty("file.encoding", "Latin-1"); System.out.println("file.encoding=" + System.getProperty("file.encoding")); System.out.println("Default Charset=" + Charset.defaultCharset()); System.out.println("Default Charset in Use=" + getDefaultCharSet()); } private static String getDefaultCharSet() { OutputStreamWriter writer = new OutputStreamWriter(new ByteArrayOutputStream()); String enc = writer.getEncoding(); return enc; } }
check 2
try this simple program import java.io.FileWriter; import java.io.IOException; public class Test { public static void main(String args[]) throws IOException { FileWriter filewrt = new FileWriter("out"); String defaultcharset = filewrt.getEncoding(); filewrt.close(); System.out.println("Default encoding is :" + defaultcharset); } }
check 3
import java.io.FileWriter; import java.io.IOException; import java.util.Locale; public class Test { public static void main(String args[]) throws IOException { FileWriter filewrt = new FileWriter("out"); String defaultcharset = filewrt.getEncoding(); filewrt.close(); System.out.println("Default encoding is :" + defaultcharset); Locale locale = Locale.getDefault(); System.out.println(locale); } }
check 4
this is teh program that i run on test import java.io.BufferedWriter; import java.io.FileWriter; public class FileWrite { public static void main(String args[]) { try { // Create file FileWriter fstream = new FileWriter("out.txt"); BufferedWriter out = new BufferedWriter(fstream); out.write("Damásio Pinto Do Carmo"); // Close the output stream out.close(); } catch (Exception e) {// Catch exception if any System.err.println("Error: " + e.getMessage()); } } }