http://blog.csdn.net/melearner/article/details/7036609 - @Test
- public void test4() {
- /**
- * inputstream和outputstream复制一个照片
- */
- InputStream fis = null;
- OutputStream fos = null;
- try {
- /**
- * InputStream输入流 OutputStream输出流
- */
- fis = new FileInputStream("d:/0.jpg");
- fos = new FileOutputStream("d:/1.jpg");
- byte[] image = new byte[1024];
- int headread = 0;
- while ((headread = fis.read(image)) != -1) {
- /**
- * 写入文件
- */
- fos.write(image, 0, headread);
- }
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- } finally {
- /**
- * 关闭输入输出流
- */
- if (fis != null) {
- try {
- fis.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- if (fos != null) {
- try {
- fos.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- }
复制代码 图片是字节流读取的 |