Test Question of the basic phase of the dark horse: read all the content in info.txt through the hacker input stream, read a line each time, extract the first text of each line and print it on the console .,

Source: Internet
Author: User

Test Question of the basic phase of the dark horse: read all the content in info.txt through the hacker input stream, read a line each time, extract the first text of each line and print it on the console .,

Package com. swift; import java. io. bufferedReader; import java. io. bufferedWriter; import java. io. fileInputStream; import java. io. fileOutputStream; import java. io. IOException; import java. io. inputStreamReader; import java. io. outputStreamWriter; public class IO_FirstLetter {public static void main (String [] args) throws IOException {/** write the following content to info.txt of the project root directory through the volume output: * Black Water is swallowed up, * immediately in the autumn. * All the content in info.txt is read through the internal input stream. Each time a row is read, the first text of each row is truncated and printed on the console. * PS: Console printing example */StringBuffer sb = new StringBuffer (); sb. append ("black water swallowed,"); sb. append ("\ r \ n"); sb. append ("immediately in autumn. "); BufferedWriter bw = new BufferedWriter (new OutputStreamWriter (new FileOutputStream (" info.txt ")," gb2312 "); bw. write (sb. toString (); bw. flush (); BufferedReader br = new BufferedReader (new InputStreamReader (new FileInputStream ("info.txt"), "gb2312"); String str; while (str = br. readLine ())! = Null) {System. out. println (str. charAt (0 ));}}}

 

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.