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("中");
  }
}
posted on 2018-03-14 15:02  文种玉  阅读(2337)  评论(0编辑  收藏  举报