base64编码和url编码


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.List;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Node;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;


/**
*
* @author yy
* 消息发送类
*/
public class MessageSender {

public static void main(String[] args) throws IOException {
BASE64Encoder base=new BASE64Encoder();
String contents = "一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十";
String s = URLEncoder.encode(base.encode(contents.getBytes()),"UTF-8");
System.out.println(contents);
System.out.println(s);

BASE64Decoder decoder=new BASE64Decoder();
byte[] de = decoder.decodeBuffer(URLDecoder.decode(s,"UTF-8"));
String s2 = new String(de);
System.out.println(s2);
}
}

你可能感兴趣的:(base64,url)