JAVA IO streaming 10 kinds of copy files examples __java

Source: Internet
Author: User
Tags readline
Class Iototal {public static void main (string[] args) {}//character input output stream one read public static void Total01 ()
        Throws IOException {FileReader fr = new FileReader ("1.txt");
        FileWriter FW = new FileWriter ("2.txt");
        int A;
        while ((A = Fr.read ())!=-1) {fw.write (a);
        } fr.close ();
    Fw.close (); }//character input output stream one character array read public static void Total02 () throws IOException {FileReader fr = new FileReader ("1.
        TXT ");
        FileWriter FW = new FileWriter ("2.txt");
        char[] arr = new char[1024 * 4];
        int Len;
        while (len = Fr.read (arr))!=-1) {fw.write (arr, 0, Len);
        } fw.close ();
    Fr.close (); }//High speed character input output stream one read public static void Total03 () throws IOException {FileReader fr = new FileReader ("1.
        TXT ");
        BufferedReader br = new BufferedReader (FR);
        FileWriter FW = new FileWriter ("2.txt"); BufferedWriter bw = new BufferedWriter (FW);
        int A;
        while ((A = Br.read ())!=-1) {bw.write (a);
        } br.close ();
    Bw.close (); }//High speed character input output stream one character array read public static void Total04 () throws IOException {FileReader fr = new FileReader ("
        1.txt ");
        BufferedReader br = new BufferedReader (FR);
        FileWriter FW = new FileWriter ("2.txt");
        BufferedWriter bw = new BufferedWriter (FW);
        char[] arr = new char[1024 * 4];
        int Len;
        while (len = Br.read (arr))!=-1) {bw.write (arr, 0, Len);
        } bw.close ();
    Br.close (); //Character buffer flow decoration method write-only unique methods public static void Total05 () throws IOException {BufferedReader br = new Buffe
        Redreader (New FileReader ("1.txt"));
        BufferedWriter bw = new BufferedWriter (New FileWriter ("2.txt"));
        String str = NULL;
            while (str = Br.readline ())!= null) {bw.write (str);
   Bw.newline ();     } br.close ();
    Bw.close (); }//Byte input/output stream one read public static void Total06 () throws IOException {fileinputstream fin = new fileinputs
        Tream ("1.txt");
        FileOutputStream fout = new FileOutputStream ("2.txt");
        int A;
        while ((A = Fin.read ())!=-1) {fout.write (a);
        } fin.close ();
    Fout.close (); }//Byte input output stream one byte array read public static void Total07 () throws IOException {fileinputstream fin = new Fileinpu
        Tstream ("1.txt");
        FileOutputStream fout = new FileOutputStream ("2.txt");
        byte[] arr = new BYTE[1024*4];
        int Len;
        while (len = Fin.read (arr))!=-1) {fout.write (Arr,0,len);
        } fin.close ();
    Fout.close (); }//high-speed byte input/output stream one read public static void Total08 () throws IOException {fileinputstream fin = new Fileinpu
        Tstream ("1.txt");
        Bufferedinputstream bin = new Bufferedinputstream (FIN); FIleoutputstream fout = new FileOutputStream ("2.txt");
        Bufferedoutputstream bout = new Bufferedoutputstream (fout);
        int A;
        while ((A = Bin.read ())!=-1) {bout.write (a);
        } bin.close ();
    Bout.close (); }//high-speed byte input-output stream read public static void total09 () of a byte array throws IOException {fileinputstream fin = new Filein
        Putstream ("1.txt");
        Bufferedinputstream bin = new Bufferedinputstream (FIN);
        FileOutputStream fout = new FileOutputStream ("2.txt");
        Bufferedoutputstream bout = new Bufferedoutputstream (fout);
        byte[] arr = new BYTE[1024*4];
        int Len;
        while (len = Bin.read (arr))!=-1) {bout.write (Arr,0,len);
        } bin.close ();
    Bout.close (); }//byte-> character-> bytes public static void Total10 () throws IOException {BufferedReader br = new Bufferedrea
    Der (New Bufferedinputstream (New FileInputStream ("1.txt")) InputStreamReader);    BufferedWriter bw = new BufferedWriter (new Bufferedoutputstream (New FileOutputStream ("1.txt", t
        Rue)));
        String line = null;
            while (line = Br.readline ())!= null) {System.out.println (line);
            Bw.write (line);
        Bw.newline ();
        } br.close ();

       Bw.close ();
        /* int len = 0;
        char[] arr = new CHAR[1024*4];
        while (len = Br.read (arr))!=-1) {bw.write (Arr,0,len);
        } bw.close (); Br.close (); */}}
Related Article

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.