byte[]  buf=new byte[1024];
int len =0;
while((len =in.read(buf))!=-1){
out.write (new String(buf,0,len).getbyte ());
这样导致我的图片打不开,然后我把最后一行代码改成了
out.write(buf,0,len);
为什么会出现这样的情况喃,大佬求解,萌新小白卑微求答。

解决方案 »

  1.   

    我这样修改图片就可以打来了,很是奇怪,为什么二进制转换string在转换回来会发生这样的问题喃
      

  2.   

    好像是这样的,我都用gbk也会出现问题,但是我都指定iso8859-1就成功了,其他码表是不是会改变数据哦
      

  3.   

    没指定编码的话,默认:ISO-8859-1。
    我觉得应该是和你读取有关
        static byte[] encode(String charsetName, char[] ca, int off, int len)
            throws UnsupportedEncodingException
        {
            StringEncoder se = deref(encoder);
            String csn = (charsetName == null) ? "ISO-8859-1" : charsetName;
            if ((se == null) || !(csn.equals(se.requestedCharsetName())
                                  || csn.equals(se.charsetName()))) {
                se = null;
                try {
                    Charset cs = lookupCharset(csn);
                    if (cs != null)
                        se = new StringEncoder(cs, csn);
                } catch (IllegalCharsetNameException x) {}
                if (se == null)
                    throw new UnsupportedEncodingException (csn);
                set(encoder, se);
            }
            return se.encode(ca, off, len);
        }