用java代碼實現Base64的轉碼和解碼


import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
/**
* 轉碼和解碼
* @author wenyuan
*/
public class Smartcoder {
//轉碼
public static String encoder(String strTest){
try {
strTest = URLEncoder.encode(strTest, "UTF-8");
System.out.println(""+strTest);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return strTest;
}
//解碼
public static String decoder(String strTest){
try {
strTest = URLDecoder.decode(strTest, "UTF-8");
System.out.println(strTest);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return strTest;
}
public static void main(String[] args) throws UnsupportedEncodingException {
// %e6%96%87%e6%b8%8a
// %E6%96%87%E6%B8%8A
// Smartcoder.decoder("%E5%B9%BF%E4%B8%9C%E7%9C%81%E6%B7%B1%E5%9C%B3%E5%B8%82%E5%8D%97%E5%B1%B1%E5%8C%BA");
Smartcoder.encoder("中");
}
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM