歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Java在命令行界面中進行輸入數據的方法

Java在命令行界面中進行輸入數據的方法

日期:2017/3/1 10:35:52   编辑:Linux編程

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