Realize the method of encoding conversion function:
Compile the Java file. Source is as follows:
Require local installation JDK 1.4)
import java.io.FileInputStream; import java.io.FileOutputStream; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; import java.nio.charset.Charset; import java.nio.CharBuffer;
public class CC {public static void main (String [] args) throws Exception {FileInputStream fi = new FileInputStream (args [0]); int length = fi.available (); FileChannel fc = fi.getChannel (); ByteBuffer buff = Bytebuffer.allocate (Length); fc.read (buff); buff.flip (); fc.close (); fi.close (); // decode using this system's default charset: buff.rewind (); // string Encoding = system.getProperty ("file.encoding"); //system.out.println (// "decoded using" // encoding // ":" // charset.forname (encoding) .decode (buff) .decode )); // // or, we could encode with something That Will Print: charset decoder = charset.Forname (args [1]); charset encoder = charset.Forname (args [2]); charbuffer cb = decoder.Decode (buff); BYTEBUFFER BUFF2 = Encoder.Encode (CB); FileOutputStream fo = new fileoutputstream (args [0]); fc = fo.getChannel (); // string filecontent = new string (buff2.Array ()); / /FC.WRITE (BYTEBUFFER.Wrap (FileContent.getbytes)); fc.write (buff2); fc.close (); Fo.close ();
2. Place cc.java in a directory (x: / cc).
3. CD x: / cc; javac cc.java; generate cc.class files.
4. Open UltraEdit (the best version 10 or more)
5. Advanced -> Tool Configuration.
6. Configure the following figure:
7. After filling out, Click Insert, SJIS-> UTF-8 will appear in the lower text box.
8. Implement UTF-8-> SJIS and other conversion.
9. Click OK, at this time, you will see the following tools under the Advanced menu:
10. After opening the Java file downloaded to the local, Click EUC-JP-> SJIS can
The Java file is converted to SJIS encoding. You can see the normal Japanese character in the UltraEdit. 11. For the conversion between Chinese GB2312, BIG5, and UTF-8, it can also be performed as above.
12. In the above manner, you can also implement the encoding conversion function in EditPlus.