zoukankan      html  css  js  c++  java
  • Java 字符终端上获取输入三种方式

    http://blog.csdn.net/hongweigg/article/details/14448731

    在Java 字符终端上获取输入有三种方式:

    1、java.lang.System.in (目前JDK版本均支持)

    2、java.util.Scanner (JDK版本>=1.5)

    3、java.io.Console(JDK版本>=1.6),特色:能不回显密码字符

    package com.srie.chapter01;
    
    import java.io.BufferedReader;
    import java.io.Console;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.util.Scanner;
    
    public class TestCalc {
    
        public static void main(String[] args) throws Exception {
            
            readBySystem();
            readByScanner();
            readByConsole();
        }
    
        private static void readByConsole() {
            System.out.println("read by console");
            Console console = System.console();
            if(console == null){
                System.out.println("console is null!");
            }else{
                String readLine = console.readLine();
                System.out.println(readLine);
            }
        }
    
        private static void readBySystem() throws IOException {
            System.out.println("read by system.in");
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
            String readLine = bufferedReader.readLine();
            System.out.println(readLine);
        }
    
        private static void readByScanner() {
            System.out.println("read by scanner:");
            Scanner scanner = new Scanner(System.in);
            String nextLine = scanner.nextLine();
            System.out.println(nextLine);
        }
    
    }
  • 相关阅读:
    IE6常见CSS解释BUG及hack
    超链接标签a
    图片标签img
    如何让一个元素始终在窗口水平垂直居中
    display属性及属性值
    设置省略号
    如何让一个图片垂直居中
    post与get的区别
    绝对路径与相对路径
    数组的操作方法
  • 原文地址:https://www.cnblogs.com/stono/p/4332641.html
Copyright © 2011-2022 走看看