「Java」StringクラスでASCIIコードを文字列に変換するサンプル
説明
public String(byte[] bytes,String charsetName)
throws UnsupportedEncodingException
指定された文字セットを使用して、指定されたバイト配列を復号化することにより、
新しいStringを構築します。
Javaコード
package com.arkgame.study.file;
import java.io.UnsupportedEncodingException;
public class AsciiDemo {
      private static byte[] cftCode = new byte[] { 37, 80, 68, 70, 45 };
      private static String cftAs = "US-ASCII";
      public static void main(String[] args) {
            String modResult = func();
            System.out.println("変換後の文字列:" + modResult);
      }
      public static String func() {
            String resStr = null;
            try {
                  resStr = new String(cftCode, cftAs);
            } catch (UnsupportedEncodingException e) {
                  // TODO 自動生成された catch ブロック
                  e.printStackTrace();
            }
            return resStr;
      }
}
結果
変換後の文字列:%PDF-