java中FileInputStream和FileOutputStream对图片操作的例子

 1 package a.ab;
 2 
 3 import java.io.FileInputStream;
 4 import java.io.FileNotFoundException;
 5 import java.io.FileOutputStream;
 6 import java.io.IOException;
 7 
 8 public class ClassA {
 9     public static void main(String[] args) {
10         try {
11             FileInputStream fis = new FileInputStream(
12                     "C:\Program Files\feiq\Recv Files\001.jpg");
13             FileOutputStream fos = new FileOutputStream(
14                     "C:\Program Files\feiq\Recv Files\003.jpg");
15             int len = 0;
16             byte[] bytes = new byte[1024];
17             try {
18                 while ((len = fis.read(bytes)) != -1) {
19                     fos.write(bytes, 0, len);
20                 }
21             } catch (IOException e) {
22                 e.printStackTrace();
23             } finally {
24                 if (fis != null) {
25                     try {
26                         fis.close();
27                     } catch (IOException e) {
28                         e.printStackTrace();
29                     }
30                 }
31                 if (fos != null) {
32                     try {
33                         fos.close();
34                     } catch (IOException e) {
35                         e.printStackTrace();
36                     }
37                 }
38             }
39         } catch (FileNotFoundException e) {
40             e.printStackTrace();
41         }
42 
43     }
44 }
View Code
原文地址:https://www.cnblogs.com/LYL-1314/p/5721113.html