- //第一种方式
- package com.rosv.io;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- public class IOStream
- {
- public static void main(String[] args) throws IOException
- {
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- String strLine = null;
- while ((strLine = br.readLine()) != null)
- {
- if ("e".equalsIgnoreCase(strLine))
- {
- break;
- }
- System.out.println(strLine);
- }
- }
- }
- //第二种方式
- package com.rosv.io;
- import java.util.Scanner;
- public class ScannerTest
- {
- public static void main(String[] args)
- {
- Scanner sc = new Scanner(System.in);
- String str = null;
- while (sc.hasNextLine())
- {
- str = sc.next();
- if ("e".equalsIgnoreCase(str))
- {
- break;
- }
- System.out.println(str);
- }
- }
- }
复制代码 |