Java-->printstream

Source: Internet
Author: User
Tags readfile

-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

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.