Bi Xiangdong _java Basic Video tutorial 19th day _io Stream (20~22)

Source: Internet
Author: User

19th Day -20-io Stream (change standard input)

static void SetIn (InputStream in) reassigns the "standard" input stream.

Static void SetOut (PrintStream out) reassigns the ' standard ' output stream.

 PackageBxD;ImportJava.io.*; Public classTransStreamDemo3 { Public Static voidMain (string[] args)throwsIOException {//not commonly usedSystem.setin (NewFileInputStream ("S.txt")); System.setout (NewPrintStream ("OUT.txt")); BufferedReader BUFR=NewBufferedReader (NewInputStreamReader (system.in)); BufferedWriter BUFW=NewBufferedWriter (NewOutputStreamWriter (System.out));        String Line;  while(line = Bufr.readline ())! =NULL) {            if("EOF". Equals (line)) Break;            Bufw.write (line);            Bufw.newline ();        Bufw.flush ();        } bufr.close ();    Bufw.close (); }}
19th Day -21-io Stream (Exception Log information)

void Printstacktrace (PrintStream s) Prints this throwable and its backtrace to the specified print stream.

 PackageBxD;ImportJava.io.PrintStream;ImportJava.text.SimpleDateFormat;Importjava.util.Date; Public classExceptioninfo { Public Static voidMain (string[] args) {Try {            //Array out-of- bounds access            int[] Array =New int[2]; System.out.println (array[3]); } Catch(Exception e) {printstream PrintStream=NULL; String Time=NewSimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"). Format (NewDate ()); Try{PrintStream=NewPrintStream ("ExceptionInfo.txt");                Printstream.println (time); //Printstream.write (Time.getbytes ());}Catch(Exception ex) {Throw NewRuntimeException ("Log file creation failed");        } e.printstacktrace (PrintStream); }   //log4j is used in the actual project.    }}
19th Day -22-io Stream (printing system Information)

static Properties getProperties () determines the current System Properties.

 package   BxD;  import   java.io.IOException;  import   Java.io.PrintStream;  import   java.util.Properties;  public  class   SystemInfo { public  static  void  main (string[] args)  Throws   IOException {Properties prop  = Syst        Em.getproperties (); Prop.list ( new  printstream ("Sysinfo.txt"     )); }}

Bi Xiangdong _java Basic Video tutorial 19th day _io Stream (20~22)

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.