byte [] b;
String utf8_value;
utf8_value = request.getParameter("NAME");//從HTTP流中取"NAME"的UTF8數(shù)據(jù)
b = utf8_value.getBytes("8859_1"); //中間用ISO-8859-1過(guò)渡
String name = new String(b, "GB2312"); //轉(zhuǎn)換成GB2312字符ServletInputStream inStream = request.getInputStream(); //取HTTP請(qǐng)求流
int size = request.getContentLength(); //取HTTP請(qǐng)求流長(zhǎng)度
byte[] buffer = new byte[size]; //用于緩存每次讀取的數(shù)據(jù)
byte[] in_b = new byte[size]; //用于存放結(jié)果的數(shù)組
int count = 0;
int rbyte = 0;
while (count < size) {
//循環(huán)讀取
rbyte = inStream.read(buffer); //每次實(shí)際讀取長(zhǎng)度存于rbyte中
for(int i=0;i<rbyte;i++) {
in_b[count + i] = buffer[i];
}
count += rbyte;
}ByteArrayOutputStream swapStream = new ByteArrayOutputStream();
byte[] buff = new byte[100]; //buff用于存放循環(huán)讀取的臨時(shí)數(shù)據(jù)
int rc = 0;
while ((rc = inStream.read(buff, 0, 100)) > 0) {
swapStream.write(buff, 0, rc);
}
byte[] in_b = swapStream.toByteArray(); //in_b為轉(zhuǎn)換之后的結(jié)果 進(jìn)入討論組討論。 新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注