JavaIO练习:FileInputStream等

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
/**
 * <span style="color:red;">IO操作:</span>
 * @author whc
 * 
 */

public class MyFileIO {
 /**
  * 文件复制功能(字节流)
  * @return string
  */
 public String testFileIOStream(){
  int b=0;
  FileInputStream infile=null;
  FileOutputStream outfile=null;
  try{
   infile = new FileInputStream("F://aaa.txt");
   outfile = new FileOutputStream("c://xxx.txt");
//   long num = 0;
   while((b=infile.read())!=-1){
    outfile.write(b);
//    num++;
   }
   infile.close();  
   outfile.close();
//   System.out.println("共读取了 "+num+" 个字节"); 
  }catch(FileNotFoundException e){
   System.out.println("文件未找到!");
   System.exit(-1);
   return "文件复制失败!";
  }catch(IOException e1){
   System.out.println("文件读取错误!");
   System.exit(-1);
   return "文件复制失败!";
  }
  return "文件复制成功";
 }
}

 javaIO练习

 

你可能感兴趣的:(java,C++,c,C#,F#)