最近用到了字符串的壓縮
看了一些相關的文章
以jsp頁面中文傳遞為例子
public class Login
extends HttpServlet {
private static final String CONTENT_TYPE =
//Initialize global variables
public void init() throws ServletException {
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request
ServletException
String name = request
name = new String(name
response
PrintWriter out = response
out
out
out
out
out
out
out
}
}
幸好
再以壓縮流為例(文件流實際上也是一樣的)
public String uncompress(byte[] cmp) {
String ret =
int i;
byte[] buf = new byte[
try {
/**
*新的方式
*/
BufferedInputStream bis = new BufferedInputStream(new GZIPInputStream(new
ByteArrayInputStream(cmp)));
/**
* 以前的方式
* 在 new InputStreamReader()的時候發生了隱含的byte到char的轉換
*/
// BufferedReader bis = new BufferedReader(new InputStreamReader(new
// GZIPInputStream(new
// ByteArrayInputStream(cmp))));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
BufferedOutputStream bos = new BufferedOutputStream(baos);
while ( (i = bis
bos
}
bos
baos
bis
ret = new String(baos
}
catch (IOException ex) {
ex
}
return ret;
}
reader是以字符為核心
我們如果今後再遇到亂碼的問題
From:http://tw.wingwit.com/Article/program/Java/hx/201311/26652.html