汉字列表

汉字列表,源于网络

/** * */ package java_rx; import java.io.File; import java.io.FileOutputStream; import java.io.FileWriter; import java.io.IOException; import java.io.OutputStreamWriter; import java.nio.ByteBuffer; import java.nio.CharBuffer; import java.nio.charset.Charset; import java.nio.charset.CharsetEncoder; /** * @author clydelou * */ public class PrintChinese { /** * @param args */ public static String convert(int n) { StringBuilder sb = new StringBuilder(); // appendCodePoint // // public StringBuilder appendCodePoint(int codePoint) // // Appends the string representation of the codePoint argument to this // sequence. // // The argument is appended to the contents of this sequence. The length // of this sequence increases by Character.charCount(codePoint). // // The overall effect is exactly as if the argument were converted to a // char array by the method Character.toChars(int) and the character in // that array were then appended to this character sequence. // // Parameters: // codePoint - a Unicode code point // Returns: // a reference to this object. // Since: // 1.5 sb.appendCodePoint(n); return sb.reverse().toString(); } public static void main(String[] args) throws IOException { // TODO Auto-generated method stub File fw_file = new File("汉字表-0.txt"); FileWriter fw = new FileWriter(fw_file); File osw_file = new File("汉字表-1.txt"); FileOutputStream fos = new FileOutputStream(osw_file); OutputStreamWriter osw = new OutputStreamWriter(fos); for (int i = 19968; i <= 40869; i++) { // getBytes // // public byte[] getBytes() // // Encodes this String into a sequence of bytes using the platform's // default charset, storing the result into a new byte array. // // The behavior of this method when this string cannot be encoded in // the default charset is unspecified. The CharsetEncoder class // should be used when more control over the encoding process is // required. // // Returns: // The resultant byte array // Since: // JDK1.1 byte[] gbkBytes0 = convert(i).getBytes("GBK"); String str0 = String.format("%x", gbkBytes0[0]); String str1 = String.format("%x", gbkBytes0[1]); String str = convert(i) + " " + Integer.toHexString(i) + " " + str0 + str1 + "/n"; fw.write(str); // toChars // // public static char[] toChars(int codePoint) // // Converts the specified character (Unicode code point) to its // UTF-16 representation stored in a char array. If the specified // code point is a BMP (Basic Multilingual Plane or Plane 0) value, // the resulting char array has the same value as codePoint. If the // specified code point is a supplementary code point, the resulting // char array has the corresponding surrogate pair. // // Parameters: // codePoint - a Unicode code point // Returns: // a char array having codePoint's UTF-16 representation. // Throws: // IllegalArgumentException - if the specified codePoint is not a // valid Unicode code point. // Since: // 1.5 char[] ca = Character.toChars(i); CharsetEncoder gbkEncoder = Charset.forName("GBK").newEncoder(); // wrap // // public static CharBuffer wrap(char[] array) // // Wraps a character array into a buffer. // // The new buffer will be backed by the given character array; that // is, modifications to the buffer will cause the array to be // modified and vice versa. The new buffer's capacity and limit will // be array.length, its position will be zero, and its mark will be // undefined. Its backing array will be the given array, and its // array offset will be zero. // // Parameters: // array - The array that will back this buffer // Returns: // The new character buffer CharBuffer cbuf = CharBuffer.wrap(ca); ByteBuffer bbuf = gbkEncoder.encode(cbuf); byte[] gbkBytes1 = bbuf.array(); str0 = String.format("%x", gbkBytes1[0]); str1 = String.format("%x", gbkBytes1[1]); str = convert(i) + " " + Integer.toHexString(i) + " " + str0 + str1 + "/n"; osw.write(str); } fw.flush(); fw.close(); osw.close(); fos.close(); System.out.println("Finished"); } }

 

你可能感兴趣的:(String,File,buffer,Parameters,character,byte)