梦幻之城

理想王国

导航

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

 

posted on 2016-07-30 15:57  梦幻之城,理想王国  阅读(1161)  评论(0编辑  收藏  举报