InputStream转为byte数组

InputStream is = request.getSession().getServletContext().getResourceAsStream("/WEB-INF/swdjzbg.png");

        ByteArrayOutputStream baos = new ByteArrayOutputStream();

        int len = 1024;

        byte tmp [] = new byte[len];

        int i ;

        while((i=is.read(tmp, 0, len))>0){

            baos.write(tmp, 0, i);

        }

        byte imgs[] = baos.toByteArray();

 

你可能感兴趣的:(Inputstream)