Karakter konverzió (UTF-8)

A karakterkészlet konverzió String objektumok esetén (J2SE 1.6-tól)

    public static String iCharSetName = "ISO-8859-2";
    public static String oCharSetName = "UTF-8";
    public static Charset iCharSet = Charset.forName(iCharSetName);
    public static Charset oCharSet = Charset.forName(oCharSetName);
 
String message = new String(item.getMessage().getBytes(iCharSet),oCharSet);

Fájl tartalom konverzió esetén:

        InputStream iStream = null;
        InputStream eStream = null;
        FileOutputStream oFileStream = null;
        Process p = null;
 
        iStream = p.getInputStream();
        String iCharSet = "cp852";
        String oCharSet = "UTF-8";
 
        BufferedReader br = new BufferedReader(new InputStreamReader(iStream, Charset.forName(iCharSet)));
 
        oFileStream = new FileOutputStream(homeDir + "out.txt",true);
        BufferedWriter oFileWriter = new BufferedWriter(new OutputStreamWriter(oFileStream, Charset.forName(oCharSet)));
 
        String iLine = null;
        while (((iLine = br.readLine()) != null)) {
           if (!(iLine = iLine.trim()).isEmpty()) {  
              oFileWriter.append( iLine + endLine );
           }
        }
 
        oFileWriter.flush();

További segítség a i18n bájt kódoláshoz itt található.