Java 把图片转换为二进制以及生成图片

2014-11-24 07:32:29 · 作者: · 浏览: 2

String path = "g:/iphone4.jpg";
File file = new File(path);


FileInputStream fis = new FileInputStream(file);
byte[] b = new byte[fis.available()];
StringBuilder str = new StringBuilder();//不建议用String


fis.read(b);


for(byte bs:b)
{
str.append(Integer.toBinaryString(bs));//转换为二进制
}


//把字节数组的图片写到另一个地方


File apple= new File("D:/apple.jpg");
FileOutputStream fos = new FileOutputStream(apple);
fos.write(b);
fos.flush();
fos.close();