Home > Back-end >  Ask why this code cannot copy pictures
Ask why this code cannot copy pictures

Time:10-08

Public static void main (String [] args) {
//TODO Auto - generated method stub
//copy (" SRC/com/ZSJ/IO/Copy01. Java ", "Copy01. TXT");
Copy (" p.p ng ", "pcopy01. PNG");
}
Public static void copy (String srcPath, String destPath) {
//1. Create the source
//source
The File SRC=https://bbs.csdn.net/topics/new File (srcPath);
//destination
The File dest=new File (destPath);//
//2. Choose flow

FileReader reader=null;
FileWriter writer=null;

Try {

Reader=new FileReader (SRC);

Writer=new FileWriter (dest);

//3. The operation section read
Char [] flush=new char [1024].//the buffer container
Int len=1;//receive length
While ((len=reader. Read (flush))!=1) {
Writer. Write (flush, 0, len);
}
//refresh
Writer. Flush ();
} the catch (FileNotFoundException e) {
e.printStackTrace();
} the catch (IOException e) {
e.printStackTrace();
} the finally {
Try {
//Alt shift z 7
//4. Release resources were shut down
//first open the back closed
If (null!={writer)
Writer. The close ();
}
} the catch (Exception e) {
//TODO: handle the exception
e.printStackTrace();
}

Try {
If (null! Reader)={
Reader. The close ();
}

} the catch (IOException e) {
//TODO Auto - generated the catch block,
e.printStackTrace();
}
}
}
  • Related