java io流读取问题

来源:互联网 发布:我的世界手机版女仆js 编辑:程序博客网 时间:2024/04/30 12:38

public class DeleteFile {

 /**
  * @param args
  * @throws Exception
  */
 public static void main(String[] args) throws Exception {
//  File file= new File("E:\\test\\hello\\2.jpg");
//  System.out.println("路径绝对:"+file.getAbsolutePath());
//  System.out.println("parent()方法:"+file.getParent());
//  System.out.println("listFiles()方法:"+file.listFiles());
  
  File newFile=new File("F:\\wo");
  File oldFile= new File("F:\\test2\\hello\\2.jpg");
  forJava(oldFile, newFile);
  
 }
 public static long forJava(File f1,File f2) throws Exception{
   System.out.println(f1.exists()+":"+f2.exists());
   if(!f2.exists()){
    f2.mkdirs();
   }
    long time=new Date().getTime();
    int length=2097152;
    FileInputStream in=new FileInputStream(f1);
    FileOutputStream out=new FileOutputStream(f2);
    byte[] buffer=new byte[length];
    while(true){
     int ins=in.read(buffer);
     if(ins==-1){
      in.close();
      out.flush();
      out.close();
      return new Date().getTime()-time;
     }else
      out.write(buffer,0,ins);
    }
  }
}


报错:F:\\wo拒绝访问;  以前碰到过这个问题,到网上查,都说是操作系统的权限问题,

其实不是的,问题出现在上面下划线处,应指定文件,而不应是目录。