Java Keyboard input data

Source: Internet
Author: User

/* Use the ReadLine method directly to complete the reading of a row of data entered by the keyboard. ReadLine is a method in the character stream BufferedReader class. The Read method of keyboard input is the method in byte stream inputstream. byte-to-character. */import java.io.*;class Transstreamdemo {public static void main (string[] args) throws ioexception{/*// Gets the keyboard entry object InputStream in=system.in;//converts a byte stream object to a character stream object, using the transform stream. Inputstreamreaderinputstreamreader isr=new InputStreamReader (in);//In order to improve efficiency, the string is efficiently manipulated by buffer technology. Use Bufferedreaderbufferedreader br=new BufferedReader (ISR); *///Keyboard entry The most common wording: BufferedReader br=new BufferedReader (new InputStreamReader (system.in)); OutputStream out=system.out;outputstreamwriter osw=new OutputStreamWriter (out); BufferedWriter bw=new BufferedWriter (OSW); String Line=null;while ((Line=br.readline ())!=null) {if (Line.equals ("Over")) Break;//system.out.println ( Line.touppercase ()); Bw.write (Line.touppercase ()); Bw.newline (); Bw.flush ();} Bw.close ();}}
/* Keyboard input reads one line, output one line */import java.io.*;class keyinput {public static void main (string[] args) throws Ioexception{keyinput ();} public static void Keyinput () throws Ioexception{inputstream in=system.in; StringBuffer sb=new StringBuffer (); while (true) {char ch= (char) in.read (); if (ch== ' \ R ') continue;if (ch== ' \ n ') {String Str=sb.tostring (); if (Str.equals ("over")); System.out.println (Str.touppercase ()); Sb.delete (0,str.length ());//emptying Container}elsesb.append (CH);}}


Java Keyboard input data

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.