new File(toFile.getAbsoluteFile() + "\\").mkdirs();
// 获取文件上传的目的地
String newfileName = toFile.toString() + "\\\\";
// 获取文件名
String fileName = fromFile.getName();
// 创建流关联文件,并写入目的地
fis = new FileInputStream(fromFile);
fos = new FileOutputStream(newfileName + fileName);
byte[] buf = new byte[1024];
int len = 0;
while ((len = fis.read(buf)) != -1) {
fos.write(buf, 0, len);
}
// 关流
fis.close();
fos.close();
}
}
复制代码
IfDemo.java Exception in thread "main" java.io.FileNotFoundException: F:\java视频\毕向东PPT源码\传智播客_Java培训_毕向东_Java基础源代码Codes\day02 (拒绝访问。) at java.io.FileInputStream.open(Native Method) at java.io.FileInputStream.<init>(FileInputStream.java:106) at com.itheima.CopyOfCopyFile.copyFiles(CopyOfCopyFile.java:73) at com.itheima.CopyOfCopyFile.copyDir(CopyOfCopyFile.java:51) at com.itheima.CopyOfCopyFile.copyDir(CopyOfCopyFile.java:46) at com.itheima.CopyOfCopyFile.main(CopyOfCopyFile.java:19)