File tree Expand file tree Collapse file tree
JavaBase/src/com/xinan/io Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package com .xinan .io ;
2+
3+ import java .io .File ;
4+ import java .io .FileInputStream ;
5+ import java .io .FileNotFoundException ;
6+ import java .io .FileOutputStream ;
7+ import java .io .IOException ;
8+ import java .io .InputStream ;
9+ import java .io .OutputStream ;
10+
11+
12+ public class StreamCopyDemo {
13+ public static void main (String [] args ) throws IOException {
14+ File srcFile = new File ("file/stream.txt" );//创建源和目标
15+ File destFile =new File ("file/stream_copy.txt" );
16+ InputStream in =new FileInputStream (srcFile );//创建输入的管道(输入流和输出对象)
17+ OutputStream out =new FileOutputStream (destFile );
18+ byte [] buffer =new byte [10 ];//创建容量为10的缓冲区(存储已经读取的字节数据)
19+ int len =-1 ;//表示已经读取了多少个字节数,
20+ while ((len =in .read (buffer ))!=-1 ){
21+ out .write (buffer ,0 ,len );
22+ }
23+ in .close ();//关闭管道
24+ out .close ();
25+ }
26+ }
You can’t perform that action at this time.
0 commit comments