我在用copyfile方法是文件拒絕訪問,不明白?
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)
2017-04-21
at java.io.FileOutputStream這個(gè)有問題