In fact, look at the title you do not think very difficult or advanced, in fact, I just follow the principle of copy to achieve, in fact, the operation of Io flow, the previous time in the study of Io stream resistance, feeling cumbersome and difficult to understand, but today re-study once again, feel very interesting, Because we are in all of the program application can not be separated from the input and output, I would like to sort out a bit about my own understanding of IO operation, I hope to learn with everyone, and now I would like to implement a simple code from a drive to copy a file to another drive letter:
Public classcopyfiletest{ Public Static void Main(String args[]) throws IOException {FileReader fr=NULL; FileWriter fw=NULL;Try{FR =NewFileReader ("C:/eula.1031.txt");//Ensure that the file existsFW =NewFileWriter ("D:/eula.1031.txt");Char[]ch=New Char[1024x768];//Create a buffer intTemp while((Temp=fr.read (CH))!=-1) {Fw.write (ch,0, temp); } }Catch(Exception ex) {System. out. println ("The file cannot be copied, please check for files ..."); }finally{if(fw!=NULL){Try{Fw.close (); }Catch(Exception e) {Throw NewRuntimeException (); } }if(fr!=NULL){Try{Fr.close (); }Catch(Exception e) {Throw NewRuntimeException (); }}} System. out. println ("Copy file success!!!"); }}
The above code is I coded in a plain text tool, it is difficult to start feeling that there is no IDE coding, or even completely do not know where to start, but need to adapt slowly, when you adapt to a period of time, with the Text tool coding is a new experience ...
Java----"Implementing Copy Functionality"