Java IO--字節(jié)流復(fù)制圖片實(shí)例
字節(jié)流用來(lái)操作圖片、視屏、音頻(進(jìn)制文件)
實(shí)例代碼:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
package learn; import java.io.*; public class Learn{ public static void main(String[] args) throws IOException { File file1= new File( "D:/a.jpg" ); File file2= new File( "D:/b.jpg" ); byte [] b= new byte [( int )file1.length()]; FileInputStream in= null ; FileOutputStream out= null ; try { in= new FileInputStream(file1); out= new FileOutputStream(file2); //沒(méi)有指定文件則會(huì)創(chuàng)建 while (in.read(b)!=- 1 ){ //read()--int,-1表示讀取完畢 out.write(b); } out.flush(); in.close(); out.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } } } |
感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!
原文鏈接:http://www.cnblogs.com/neu-student/p/6375763.html