2014/9/22

Source: Internet
Author: User

1
System. In

1 public class wori // set system with inputstreamreader first. in, and then use bufferedreader. This is a common method 2 {3 Public static void main (string ARGs []) 4 {5 inputstreamreader A = new inputstreamreader (system. in); // system. in is the reference of the inputstream parent class 6 bufferedreader B = new bufferedreader (a); 7 string S = NULL; 8 Try 9 {10 while (S = B. readline ())! = NULL) // use the bufferedreader method Readline () 11 {12 if (S. equalsignorecase ("exit") // 13 {14 break; 15} 16 system. out. println (S. touppercase (); 17} 18 B. close (); // B close 19} 20 catch (ioexception e) 21 {22 E. printstacktrace (); 23} 24} 25}

 


2
Datainputstream, dateoutputstream, bytearrayinputstream, and bytearrayoutputstream are used to directly read and write basic data types.

Public class wori {public static void main (string ARGs []) {bytearrayoutputstream baos = new bytearrayoutputstream (); // allocate memory to a byte array, dataoutputstream dos = new dataoutputstream (baos); // try {dos. writedouble (math. random (); // bytearrayinputstream BAIS = new bytearrayinputstream (baos. tobytearray (); // tobytearray () returns a byte array as the node datainputstream Dis = new datainputstream (BAIS); system. out. println (DIS. readdouble (); // dos. close (); DIS. close ();} catch (ioexception e) {system. exit (-1 );}}}

 


3
Printstream

public class wori{    public static void main(String args[])    {        PrintStream ps = null;        try        {            FileOutputStream fos = new FileOutputStream("d:/1.txt");            ps = new PrintStream(fos);        }        catch(IOException e)        {            System.exit(0);        }        System.setOut(ps);                               //        int i = 0;        while(i < 100)        {            System.out.println(i);            i++;        }        ps.close();    }}

 

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.