Dmi*_*riy 0 java character utf-8 inputstreamreader
我使用InputStreamReader传输压缩图像。InflaterInputStream用于解压缩图像
InputStreamReader infis =
new InputStreamReader(
new InflaterInputStream( download.getInputStream()), "UTF8" );
do {
buffer.append(" ");
buffer.append(infis.read());
} while((byte)buffer.charAt(buffer.length()-1) != -1);
Run Code Online (Sandbox Code Playgroud)
但是所有非拉丁字符都变为“?” 并且图像损坏了http://s019.radikal.ru/i602/1205/7c/9df90800fba5.gif
通过传输未压缩的图像,我使用了BufferedReader,并且一切正常
BufferedReader is =
new BufferedReader(
new InputStreamReader( download.getInputStream()));
Run Code Online (Sandbox Code Playgroud)
阅读器/书写器类旨在与文本(基于字符)的输入/输出一起使用。
压缩图像是二进制的,您需要使用InputStream / OutputStream或nio类来传输二进制数据。
下面给出了使用InputStream / OutputStream的示例。本示例将接收到的数据存储在本地文件中:
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
bis = new BufferedInputStream(download.getInputStream());
bos = new BufferedOutputStream(new FileOutputStream("c:\\mylocalfile.gif"));
int i;
// read byte by byte until end of stream
while ((i = bis.read()) != -1) {
bos.write(i);
}
} finally {
if (bis != null)
try {
bis.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
if (bos != null)
try {
bos.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3833 次 |
| 最近记录: |