Reads files row by row and writes files row by row

Source: Internet
Author: User

I/O Stream-related classes in Java are "too rich", and people with difficult choices cannot start. Of course, this cainiao does not know much about Java I/O. I am used to using the nputstrem and outsteam subclasses to process binary streams. I use reader, child classes related to writer are used to process streams such as text files. The buffer mechanism is used to improve efficiency. I feel that the buffer mechanism is mostly a dirty stream. I don't know what buffer mechanism the binary system has. I can't solve it by Google. I feel that the posts in the blog garden are generally higher than those in csdn. In addition, I can see that all the articles in the blog Park are of high quality. In contrast, what I wrote by cainiao will remind me of the sentence: Too young too naive! OK. The title is the content of this note. The Code is as follows:

 1 package io.newline; 2  3 import java.io.BufferedReader; 4 import java.io.BufferedWriter; 5 import java.io.FileNotFoundException; 6 import java.io.FileReader; 7 import java.io.FileWriter; 8 import java.io.IOException; 9 import java.io.PrintWriter;10 11 public class CopyLine {12     public static void main(String[] args) {13         try {14             BufferedReader br = new BufferedReader(new FileReader("F:/a/s.txt"));15 16             PrintWriter out = new PrintWriter(new BufferedWriter(17                     new FileWriter("F:/a/t.txt", true)));18 19             String line = null;20 21             while ((line = br.readLine()) != null) {22                 System.out.println(line);23                 out.println(line);        //向t.txt写入一行24             }25             if (br != null) {26                 br.close();27             }28             if (out != null) {29                 out.close();30             }31 32         } catch (FileNotFoundException e) {33             e.printStackTrace();34         } catch (IOException e) {35             e.printStackTrace();36         }37 38     }39 40 }

 

Reads files row by row and writes files row by row

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.