public static void copyFile(File srcFile,File destFile)throws IOException{
if(!srcFile.exists()){
throw new IllegalArgumentException("文件"+srcFile+"不存在");
}
if(!srcFile.isFile()){
throw new IllegalArgumentException(srcFile+"不是文件");
}
FileInputStream in=new FileInputStream(srcFile);
FileOutputStream out=new FileOutputStream(destFile);
byte[] buf=new byte[8*1024];
int b;
while((b=in.read(buf,0,buf.length))!=-1){
out.write(buf,0,b);
out.flush();
}
in.close();
out.close();
}
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
try{
IOUtil.copyFile(new File("C:\\2345下载\\Test1.java"), new File(
"C:\\2345下载"));
}catch (IOException e) {
// TODO: handle exception
e.printStackTrace();
}
}
java.io.FileNotFoundException: C:\2345下载 (拒绝访问。)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:179)
at java.io.FileOutputStream.<init>(FileOutputStream.java:131)
at package1.IOUtil.copyFile(IOUtil.java:62)
at package1.IOUtilTest3.main(IOUtilTest3.java:15)
at java.io.FileOutputStream这个有问题