Home > Back-end >  IO stream copy directory code running problem
IO stream copy directory code running problem

Time:11-05

A great god give directions: the code while the copy directory to copy all the files but will run error, could you tell me what is the specific error?
I think it's caused by the recursive error, homo habilis some directions,

Import the Java. IO. *;

Public class CopyDir {
Public static void copyDirector (File needCopy, File putPath) {
String name=needCopy. GetName ();//directory name
The File [] sub=needCopy. ListFiles ();//sub files in the directory
String path=putPath. GetAbsolutePath ();//target absolute path

The File makePath=new File (path + "\ " + name);//need to be created directory
MakePath. The mkdir ();//create a directory
String newPath=makePath. GetAbsolutePath ();//the creation of the absolute path


If (sub. Length==0) {
return;
}

FileInputStream a1=null;
FileOutputStream b2=null;
For (the File temp: sub) {
String tempName=temp. GetName ();//child file name

{if (temp. IsDirectory ())
CopyDirector (temp, makePath);
}
Try {
A1=new FileInputStream (temp);
B2=new FileOutputStream (+ tempName newPath + "\ ");
Byte [] x=new byte (1024 * 1024),
Int readCound=0;
While ((readCound=a1. Read (x))!=1) {
B2. Write (x, 0, readCound);
}
} the catch (FileNotFoundException e) {
e.printStackTrace();
} the catch (IOException e) {
e.printStackTrace();
} the finally {
Try {
A1. The close ();
} the catch (IOException e) {
e.printStackTrace();
}
Try {
B2. The close ();
} the catch (IOException e) {
e.printStackTrace();
}
}
}

}
}

Error message:
Java. IO. FileNotFoundException absolute path of the file (access denied,)
The at Java. The base/Java. IO. FileInputStream. Open0 (Native Method)
The at Java. The base/Java. IO. FileInputStream. Open (212) a FileInputStream. Java:
The at Java. The base/Java. IO. FileInputStream. & lt; init> (a FileInputStream. Java: 154)
At com. LiuZeShen. JavaSE. Copy. CopyDir. CopyDirector (CopyDir. Java: 29)
  • Related