Java Io reads files from the local device and writes them to another local file.

Source: Internet
Author: User

JAVA Code is as follows:

Package hand. wang. test; </P> <p> Import Java. io. fileinputstream; <br/> Import Java. io. fileoutputstream; <br/> Import Java. io. ioexception; <br/> Import Java. io. inputstream; <br/> Import Java. io. outputstream; <br/> Import java.net. malformedurlexception; </P> <p> public class readwritefile {<br/>/** <br/> * read data from the primary file 11.txtand write it into the primary file 12.txt <br/> * @ author zhoujianwang <br/> * <br/> */<br/> Public static Vo Id main (string [] ARGs) throws ioexception {<br/> // input stream <br/> inputstream in = new fileinputstream ("D:/11.txt "); <br/> // output stream <br/> outputstream out = new fileoutputstream ("D:/12.txt", true ); </P> <p> try {<br/> byte [] buffer = new byte [1024]; <br/> while (true) {<br/> int byteread = in. read (buffer); <br/> If (byteread =-1) <br/> break; <br/> out. write (buffer, 0, byteread); <br/>}</P> <p> Catch (malformedurlexception ex) {<br/> system. err. println (ARGs [0] + "is not a URL Java understands. "); <br/>}finally {<br/> If (in! = NULL) <br/> in. Close (); <br/> If (OUT! = NULL) {<br/> out. Close (); <br/>}< br/>}

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.