「java入門」java.util.Base64のサンプル
1.Javaコード
package sample;
import java.io.UnsupportedEncodingException;
import java.util.Base64;
public class Base64EncodeDemo {
public static void main(String[] args) {
String basicEncoded;
try {
basicEncoded = Base64.getEncoder().encodeToString(“subjects?tokyo".getBytes(“UTF-8"));
System.out.println(“Basic Alphabet: " + basicEncoded);
String urlEncoded = Base64.getUrlEncoder().encodeToString(“subjects?tokyo".getBytes(“UTF-8"));
System.out.println(“URL Alphabet: " + urlEncoded);
} catch (UnsupportedEncodingException e) {
// TODO 自動生成された catch ブロック
e.printStackTrace();
}
}
}
2.結果
Basic Alphabet: c3ViamVjdHM/dG9reW8=
URL Alphabet: c3ViamVjdHM_dG9reW8=