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 ));}}}