Java在命令行界面中进行输入数据的方法


How to input your personal data from the default command interface.

It used the System.in.read, contrast to the System.out.print.

  1. package com.han;  
  2.   
  3. import java.io.*;  
  4. /** 
  5.  * How to input your personal data from the default command interface. 
  6.  * <p> 
  7.  * It used the System.in.read, contrast to the System.out.print. 
  8.  * @author han 
  9.  * 
  10.  */  
  11. public class InputSystem{  
  12.     public static void main(String args[]){  
  13.         byte[] buffer=new byte[512];  
  14.         try {  
  15.             System.out.print("请你输入: ");  
  16.             System.in.read(buffer);//input your data, and ends with a "Return" key.   
  17.         } catch (IOException e) {  
  18.             // TODO Auto-generated catch block   
  19.             e.printStackTrace();  
  20.         }  
  21.         String str=new String(buffer);  
  22.           
  23.         System.out.println("what you input is : "+str);  
  24.     }  
  25. }   

相关内容