字节流用来操作图片、视屏、音频(进制文件)
实例代码:
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); //没有指定文件则会创建 while (in.read(b)!=- 1 ){ //read()--int,-1表示读取完毕 out.write(b); } out.flush(); in.close(); out.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } } } |
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
原文链接:http://www.cnblogs.com/neu-student/p/6375763.html