Charset encoding test : Charset « File Input Output « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Collections Data Structure
8. Database SQL JDBC
9. Design Pattern
10. Development Class
11. Email
12. Event
13. File Input Output
14. Game
15. Hibernate
16. J2EE
17. J2ME
18. JDK 6
19. JSP
20. JSTL
21. Language Basics
22. Network Protocol
23. PDF RTF
24. Regular Expressions
25. Security
26. Servlets
27. Spring
28. Swing Components
29. Swing JFC
30. SWT JFace Eclipse
31. Threads
32. Tiny Application
33. Velocity
34. Web Services SOA
35. XML
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java » File Input Output » CharsetScreenshots 
Charset encoding test

import java.nio.ByteBuffer;
import java.nio.charset.Charset;

public class MainClass {
  public static void main(String[] argvthrows Exception {
    String input = "\u00bfMa\u00f1ana?";

    // The list of charsets to encode with
    String[] charsetNames = "US-ASCII""ISO-8859-1""UTF-8""UTF-16BE""UTF-16LE""UTF-16",
    // "X-ROT13" // This requires META-INF/services
    };
    for (int i = 0; i < charsetNames.length; i++) {
      doEncode(Charset.forName(charsetNames[i]), input);
    }
  }
  private static void doEncode(Charset cs, String input) {
    ByteBuffer bb = cs.encode(input);
    System.out.println("Charset: " + cs.name());
    System.out.println("  Input: " + input);
    System.out.println("Encoded: ");

    for (int i = 0; bb.hasRemaining(); i++) {
      int b = bb.get();
      int ival = ((intb0xff;
      char c = (charival;
      // print index number
      System.out.print("  " + i + ": ");
      // print the hex value of the byte
      System.out.print(Integer.toHexString(ival));
      System.out.println(" (" + c + ")");
    }
  }
}

           
       
Related examples in the same category
1. List the Charset in your system
2. Translate Charset
www_.j__ava___2s__.__c___om__ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.