Java----"Implementing Copy Functionality"

Source: Internet
Author: User

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"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.