import java.io.*;public class ReadIn{
public static void main(String[] args){
try{
byte[] r = new byte[50];
System.out.println("Please input data:");
System.in.read(r);
String str = new String(r);
System.out.println(str);
}catch(Exception e){
System.out.println("Hello!");
}
}}运行一下试试!
public static void main(String[] args){
try{
byte[] r = new byte[50];
System.out.println("Please input data:");
System.in.read(r);
String str = new String(r);
System.out.println(str);
}catch(Exception e){
System.out.println("Hello!");
}
}}运行一下试试!
解决方案 »
- 传智播客的入学测试题—来看看自己基础如何吧
- 对于查找linear结构的数据的时候,用直接循环查询还是先排序然后binary search好?
- 请教大家一个问题:请问有没有一个API可以接收字符串,如:2005-09-23 18:35:30.0 直接可以转为时间日期??????
- 请问ListIterator和Iterator有何区别!!
- JBuilder GUI Builder 乱跳问题
- 各位大哥大姐们:小弟初学Java2,急需看一些源代,请求帮助如何获取。
- 如何得到当前日期3个月后的日期
- 哪儿有较好的java中文资料与jbuilder的中文资料<我是一个新手>
- 迷茫,请各位指点迷经,关于vc++和java
- 在线等,页面间传值,传对象问题,gwt如何实现页面间传值
- §散分顺便答个小问题§static vs. override◎◎◎
- 如何生成一个二叉树
用System.in.read输入的时候还是把你输入的字符回显出来了啊?!我想先读入,再显示啊!
c中很好办的呀!
java难道就这么弱吗?刚开始学习java,可不要给我太大的打击哦~~~~~!
你说的这个办法我觉得......!
谢谢回复!
C当然支持了,DOS还有UNIX系统,在文本模式下都可以用
char *getpass(const char *prompt)函数完成从屏幕输入,
但不回显的功能。
如今的WIN2000/XP系统的故障控制台里不也有这个吗?就是
要进入是要输入口令,但口令是不回显的。JAVA的输入输出流那么丰富,不知有没有这种类似的方法呢??
好像ORACLE在命令行下输口令也是不回显的耶,那说明JAVA一定
可以。关注……
不像c 中的printf("%d", a);....
好像在java里面ASCII 編碼不是很 廣泛?
對不起
我只學JAVA不久
现在的环境是控制台啊?!到底有没有办法呢,各位?
Command-Line Input MaskingIn contrast to AWT/Swing, there are no special APIs for masking command-line input in Java. This is a feature that has been asked for by many developers, who would like to provide a login screen for command-line, text-based Java applications. One way to address this problem is to use the Java Native Interface (JNI). But this could be difficult for some Java developers who do not know C/C++, or who want to stay with 100% pure Java code. Here I provide a solution to this problem. I follow the Unix approach to login screens, where the password is not echoed on the screen at all. To do this, I make use of threads. The MaskingThread class, shown in Code Sample 1, attempts to erase characters echoed to the console.
作者的方法我试过了,就是有点抖动,也不算很稳定,但大部分情况应该还是使用的,其实使用jni我觉得不失为一种好办法。至于java弱不弱,我到不太同意楼主的看法,男人能直接生孩子吗,不见得弱吧。
哈哈,大侠见笑!如果C能让人生孩子,而J不能让人生孩子,这难道还没有说明J比C弱吗(起码是在某些方面^_^)?
也许是各有千秋吧?!玩笑而已,谢谢回答!
public class input{
public static void main(String args[]) throws IOException
{
try {
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
String response;
while((response=in.readLine())!=null)
{
System.out.println(response);
}
in.close();
} catch (IOException e)
{
System.out.println(e.getMessage());
}
}
}
在你的代码:response=in.readLine())这部分中,你输入的时候它已经回显出来了。我得要求是在输入的时候不要显示出来,我读取了输入后在按照我的想法显示!谢谢回答!
我的意思你还没有明白。我的意思是在你输入的时候不要显示出来!也就是说用System.in.read函数的时候你输入时要屏幕上没有显示你的输入!
明白了吗?
while((response=in.readLine())!=null)
{
System.out.println(response);
}
System.out.println(response);//这句是用来输出的,while里已经把字符赋给了response.
response本身是String类型的.里面该如何处理是你自己的事情了.
笨!!!
in.readLine() 也有回显的啊!你好好试试看!笨!!!
呵呵,开玩笑的,谢谢回答!但in.readLine() 确实有回显的啊!如何呢?
BufferedReader(isr);
readLine();
了
public class testinput{
public static void main(String args[]) throws IOException
{
try {
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
String response;
int i;
response=in.readLine();
for(i=0;i<response.length();i++)
{
System.out.print(response.charAt(i)-64);
}
in.close();
} catch (IOException e)
{
System.out.println(e.getMessage());
}
}
}
这是正式的源代码,其实就是稍微改动一下. String类的方法,你不会一点也不懂吧
首先,谢谢您这么热情的回答!看来这个问题非得您解决了!但您的每次回答都不是我要的答案!
我得问题是我从键盘输入的时候输入信息没不要显示出来!也就是说你键盘中输入什么,我取职之前没有显示出来,可是你用的这个函数response=in.readLine(),你在输入的时候他已经把你输入的东西显示出来了。这个不符合我得要求。比如你要在控制台下做一个密码输入的接口,如果你输入的时候就显示出来了这个还有什么用?!这次明白了我得需求没有?谢谢回答!
jimjxr(宝宝猫)
mummy_zc(水煮鱼)
难道就这么算了?
假如有个线程1在不断的System.out.println("kkkxxxtest");(每隔一段时间输出一次)
我现在在控制台输入我要字符串,比如输入:测试啦!!!!!测试...还在输入
输入一半的时候线程1输出了kkkxxxtest
这下我的输入回显折行,也就是屏幕显示成了
测试啦!!!!!测kkkxxxtest
试...还在输入