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();
- }
- }
- }
- }
- }
复制代码
|
|