如何从Java中的键盘获取String对象? [英] how to get a String object from the keyboard in Java?

查看:161
本文介绍了如何从Java中的键盘获取String对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,我想获得一个"HelloWorld!"从Java键盘中获得,我将不胜感激

for example,I want to get a "HelloWorld!" from the keyboard in Java,I will appreciate
if you can show the code.

推荐答案

这是一个简单的代码段,请阅读键盘,直到按下Enter键为止.

Here is a simple snippet, reading the keyboard until the Enter-button is hit.

import java.io.*;


class MyClass

{
	public static void main(String[] args) throws IOException{

		//define String for input
                 String Read= ""; 
		
		//instantiate InputStreamReader for Textstream
		InputStreamReader Reader= new InputStreamReader(System.in);

                //instantiate BufferedReader for buffering the stream
		BufferedReader BufferedIn= new BufferedReader(Reader);

		//while Enter is not hit, the input stream is read from keyboard
                Read= BufferedIn.readLine();
			
			
			
		}
	}
}


这篇关于如何从Java中的键盘获取String对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆