posts - 104,  comments - 34,  trackbacks - 0

          package demo;

          import java.io.File;  
          import java.io.FileWriter;  
          import java.io.IOException;  
          import java.io.PrintWriter;  
           
          /** 
           * @date 2009-3-11 
           * @author Xing,Xiudong 
           * @Email:xingxiuodng[at]gmail.com 
           * @index:http://blog.csdn.net/xxd851116 
           */ 
          public class CoderUtils {  
           
              public static char ascii2Char(int ASCII) {  
                  return (char) ASCII;  
              }  
           
              public static int char2ASCII(char c) {  
                  return (int) c;  
              }  
           
              public static String ascii2String(int[] ASCIIs) {  
                  StringBuffer sb = new StringBuffer();  
                  for (int i = 0; i < ASCIIs.length; i++) {  
                      sb.append((char) ascii2Char(ASCIIs[i]));  
                  }  
                  return sb.toString();  
              }  
           
              public static String ascii2String(String ASCIIs) {  
                  String[] ASCIIss = ASCIIs.split(",");  
                  StringBuffer sb = new StringBuffer();  
                  for (int i = 0; i < ASCIIss.length; i++) {  
                      sb.append((char) ascii2Char(Integer.parseInt(ASCIIss[i])));  
                  }  
                  return sb.toString();  
              }  
           
              public static int[] string2ASCII(String s) {// 字符串轉(zhuǎn)換為ASCII碼  
                  if (s == null || "".equals(s)) {  
                      return null;  
                  }  
           
                  char[] chars = s.toCharArray();  
                  int[] asciiArray = new int[chars.length];  
           
                  for (int i = 0; i < chars.length; i++) {  
                      asciiArray[i] = char2ASCII(chars[i]);  
                  }  
                  return asciiArray;  
              }  
           
              public static String getIntArrayString(int[] intArray) {  
                  return getIntArrayString(intArray, ",");  
              }  
           
              public static String getIntArrayString(int[] intArray, String delimiter) {  
                  StringBuffer sb = new StringBuffer();  
                  for (int i = 0; i < intArray.length; i++) {  
                      sb.append(intArray[i]).append(delimiter);  
                  }  
                  return sb.toString();  
              }  
           
              public static String getASCII(int begin, int end) {  
                  StringBuffer sb = new StringBuffer();  
                  for (int i = begin; i < end; i++) {  
                      sb.append(i).append(":").append((char) i).append("\t");  
                      // sb.append((char) i).append("\t");  
                      if (i % 10 == 0) {  
                          sb.append("\n");  
                      }  
                  }  
                  return sb.toString();  
              }  
           
              public static String getCHASCII(int begin, int end) {  
                  return getASCII(19968, 40869);  
              }  
           
              public static void showASCII(int begin, int end) {  
                  for (int i = begin; i < end; i++) {  
                      // System.out.print(i + ":" + (char) i + "\t");  
                      System.out.print((char) i + "\t");  
                      if (i % 10 == 0) {  
                          System.out.println();  
                      }  
                  }  
              }  
           
              public static void showCHASCII() {  
                  showASCII(19968, 40869);  
              }  
           
              public static void showIntArray(int[] intArray) {  
                  showIntArray(intArray, ",");  
              }  
           
              public static void showIntArray(int[] intArray, String delimiter) {  
                  for (int i = 0; i < intArray.length; i++) {  
                      System.out.print(intArray[i] + delimiter);  
                  }  
              }  
           
              public static void createFile(String filePathAndName, String fileContent)  
                      throws IOException {  
           
                  String filePath = filePathAndName;  
                  filePath = filePath.toString();  
                  File myFilePath = new File(filePath);  
                  if (!myFilePath.exists()) {  
                      myFilePath.createNewFile();  
                  }  
                  FileWriter resultFile = new FileWriter(myFilePath);  
                  PrintWriter myFile = new PrintWriter(resultFile);  
                  String strContent = fileContent;  
                  myFile.println(strContent);  
                  myFile.close();  
                  resultFile.close();  
              }  
           
              public static void main(String[] args) throws IOException {  
           
                  String s = "好好學(xué)習(xí)!天天向上!————笑的自然 2009年3月11日";  
                  showIntArray(string2ASCII(s), " ");  
                  System.out.println();  
                  System.out.println(ascii2String(string2ASCII(s)));  
                  createFile("c:\\console_ch.txt", getCHASCII(0, 50000));  
              }  
           

          posted on 2010-08-06 17:59 末日風(fēng)情 閱讀(5714) 評(píng)論(0)  編輯  收藏 所屬分類: java編程
          <2010年8月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          2930311234

          常用鏈接

          留言簿(4)

          隨筆分類

          隨筆檔案

          搜索

          •  

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 黄平县| 靖远县| 淮北市| 阳新县| 景德镇市| 内江市| 家居| 青阳县| 紫金县| 射阳县| 周宁县| 阳城县| 大安市| 余江县| 武乡县| 河北省| 华阴市| 锡林郭勒盟| 克什克腾旗| 息烽县| 金秀| 黑山县| 石阡县| 襄城县| 纳雍县| 庆安县| 始兴县| 高尔夫| 黄梅县| 平顺县| 南康市| 曲麻莱县| 丰顺县| 榆中县| 滦平县| 和顺县| 苏尼特右旗| 东山县| 长沙市| 赤壁市| 南雄市|