黑马程序员技术交流社区
标题:
io 复制文件
[打印本页]
作者:
fmi110
时间:
2015-9-7 23:44
标题:
io 复制文件
a
package InOutDemo;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class InOutDemo2 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
//定义输出流和输入流并初始化
FileOutputStream fos = null;
FileInputStream fin = null;
try{
fos = new FileOutputStream("E:\\copy.txt",true);
fin = new FileInputStream("Demo1.java");
//读取文件
int by = 0;
while((by = fin.read())!= -1){
fos.write(by);
}
System.out.println("copy done!!");
}
catch(IOException e){
e.printStackTrace();
}
finally{
if(fin != null){
try {
fin.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(fos != null){
try {
fos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
复制代码
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2