-I don't want to use read, write after use, feel is very convenient ...
PackageCom.dragon.java.hwletter;ImportJava.io.BufferedReader;ImportJava.io.BufferedWriter;ImportJava.io.File;ImportJava.io.FileOutputStream;ImportJava.io.FileReader;Importjava.io.IOException;ImportJava.io.InputStreamReader;ImportJava.io.OutputStreamWriter;ImportJava.util.Scanner;/** Write a program to achieve the following function A: Create a directory under the C-disk letter B: The following options are displayed on the console: 1 See the Leave bar 2 compose a leave bar C: If the user chooses 2, the user is prompted to compose the leave bar and the composition is credited to the letter folder. The format is as follows: Wangbaoqiang: Leave Date: August 15, 2016 leave reason: Sue the court Ma Song Divorce ... Take a day off first. D: If the user chooses 1, the content of the leave bar is output in the console. */ Public classTest {Private StaticString FilePath = "D:/workspace/08-15/src/com/dragon/java/hwletter/letter/letter.txt"; Private StaticString line =NULL; Public Static voidMain (String args[]) {Scanner Scanner=NewScanner (system.in); NewFile (Filepath.replace ("/letter.txt", "" ") . Mkdirs (); while(true) {System.out.println ("1 See the Leave section 2 write the Leave article"); Switch(Scanner.nextint ()) { Case1: if(! (NewFile (FilePath). Exists ())) {System.out.println ("There is no leave yet!" "); Continue; } readFile (); Break; Case2: WriteFile (); Break; default: System.out.println ("Wrong input!" ..."); Break; } } } Private Static voidReadFile () {System.out.println ("Leave section:"); BufferedReader BR=NULL; Try{br=NewBufferedReader (NewFileReader (FilePath)); while(line = Br.readline ())! =NULL) {System.out.println (line); } } Catch(IOException e) {System.out.println (e); } } Private Static voidWriteFile () {System.out.println ("Please write the Leave:"); BufferedWriter BW=NULL; Try{bufferedreader br=NewBufferedReader (NewInputStreamReader (system.in,"GBK")); NewFile (FilePath). CreateNewFile (); Bw=NewBufferedWriter (NewOutputStreamWriter (NewFileOutputStream (FilePath)); while(true) { line=Br.readline (); if("End". Equals (line)) { Break; } Else if(line = =NULL) {br.close (); Break; } bw.write (line); Bw.newline (); } } Catch(IOException e) {System.out.println (e); } finally { Try { //br.close ();Bw.close (); } Catch(IOException e) {System.out.println (e); } } }}
--but later Android is not printstream ...
Java-->printstream