Java IO buffer Copy file

Source: Internet
Author: User

Directly write the code of the class and the package itself import create, hand hit very tired

public static void Main (String args[]) {

FileReader Fr=null; File input stream

FileWriter Fw=null; File output stream

BufferedReader Br=null; Character buffer input stream

BufferedWriter Bw=null; Character Buffer output stream

try{

File F = new file ("F:\\ha.txt");

Fr =new FileReader (f); Read the file F

File s =new file ("F:\\haha.txt"); Copy the generated file name

FW =new FileWriter (s); Write to S.

BR =new BufferedReader (FR); Buffer Storage FR Content

BW = new BufferedWriter (FW); Contents of buffer Memory write FW

Char c [] =new char[(int) (F.length ())]; The length of the character C is the length of the F file

int Len=br.read (c); Define an intermediate variable to accept C

Bw.writer (C,0,len);

System.out.print (New String (C,0,len)); Need to be aware of type conversions

}catch (FileNotFoundException e) {

E.printstacktrace ();

}catch (IOException e) {

E.printstacktrace ();

}finally{

try{

Br.close ();

Bw.close ();

}catch (IOException e) {

E.printstacktrace ();

}

}

}

Java IO buffer Copy file

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.