Java IO operations

Source: Internet
Author: User

Automatic resource Management (ARM) is introduced in Java7, and resources in try () {}catch{}finally{}, () are freed automatically after the program runs.

File stream is divided into input stream and output stream, typical usage

FileReader FR = new FileReader ("Poem.txt"); Read an existing file
FileWriter FW = new FileWriter ("NewPoem2.txt");//write to a specific name file (no first created), overwrite

char[] Cbuf = new CHAR[32]; Reader and writer Read and write in character units
int hasread = 0; Returns the number of reads at one time
while ((Hasread = Fr.read (cbuf)) > 0)
{
Fw.write (Cbuf,0,hasread);
}

FileInputStream fis = new FileInputStream ("Poem.txt");
FileOutputStream fos = new FileOutputStream ("NewPoem.txt"))
byte[] Bbuf = new BYTE[32]; InputStream and OutputStream read-write in bytes
int hasread = 0;
while ((Hasread = Fis.read (bbuf)) > 0)
{
Fos.write (Bbuf,0,hasread);

}

Java IO operations

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.