Java在命令行界面中进行输入数据的方法
Java在命令行界面中进行输入数据的方法
How to input your personal data from the default command interface.
It used the System.in.read, contrast to the System.out.print.
- package com.han;
- import java.io.*;
- /**
- * How to input your personal data from the default command interface.
- * <p>
- * It used the System.in.read, contrast to the System.out.print.
- * @author han
- *
- */
- public class InputSystem{
- public static void main(String args[]){
- byte[] buffer=new byte[512];
- try {
- System.out.print("请你输入: ");
- System.in.read(buffer);//input your data, and ends with a "Return" key.
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- String str=new String(buffer);
- System.out.println("what you input is : "+str);
- }
- }
评论暂时关闭