Java Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

Java Examples

Quick Start
Java Unicode
Java Certs
Java Email
Java Encryption
Java FTP
HTML-to-XML
Java HTTP
Java IMAP
Java MHT
Java MIME
Java RSA
Java S/MIME
Java Signatures
Java Socket
Java Spider
Java Tar
Java Upload
Java XML
Java XMP
Java Zip

More Examples...
Email Object
POP3
SMTP
RSS
Atom
String
Byte Array
Self-Extractor
Service
PPMD
Deflate
DH Key Exchange
DSA

Unreleased...
Bzip2
LZW
Bz2
Icon

 

 

 

 

 

 

 

Shift_JIS to iso-2022-jp Conversion

Convert Shift_JIS to iso-2022-jp

Download Chilkat Java Library

import com.chilkatsoft.*;

public class ChilkatExample {

  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[])
  {
    CkCharset charset = new CkCharset();

    //  Any string argument automatically begins the 30-day trial.
    boolean success;
    success = charset.UnlockComponent("30-day trial");
    if (success != true) {
        System.out.println("Charset component unlock failed");
        return;
    }

    //  Set the "To" and "From" charsets:
    charset.put_FromCharset("shift_JIS");
    charset.put_ToCharset("iso-2022-jp");

    //  To do file-to-file conversion, call ConvertFile.
    //  The shift_JIS sample file is downloadable from this URL:
    //  http://www.chilkatsoft.com/testData/japanese_shiftJis.txt
    success = charset.ConvertFile("japanese_shiftJis.txt","japanese_iso2022jp.txt");
    if (success != true) {
        System.out.println(charset.lastErrorText());
    }
    else {
        System.out.println("Success");
    }

    //  To do memory-to-memory conversion, load the text data
    //  into a CkByteData, then convert:
    CkByteData srcTxt = new CkByteData();

    success = srcTxt.loadFile("japanese_shiftJis.txt");
    if (success != true) {
        System.out.println("Failed to load source Shift_JIS text file");
        return;
    }

    CkByteData destTxt = new CkByteData();

    //  Convert Shift_JIS to Japanese JIS (iso-2022-jp)
    success = charset.ConvertData(srcTxt,destTxt);
    if (success != true) {
        System.out.println(charset.lastErrorText());
        return;
    }

    success = destTxt.saveFile("out.txt");
    if (success != true) {
        System.out.println("Failed to save output file");
        return;
    }

    //  Access the iso-2022-jp bytes like this:
    byte[] txtData;
    txtData = destTxt.toByteArray();
  }
}

 

Need a specific example? Send a request to support@chilkatsoft.com

© 2000-2008 Chilkat Software, Inc. All Rights Reserved.