System.in 这个in就是默认好的读控制台的对象....
解决方案 »
- why? btnExport_java.lang.NullPointerException
- 用java做游戏 如何实现图片背景的连续啊 据说是使用什么多重缓冲技术,求高手教教我啊
- 用poi读取EXCEL问题
- 接口中的方法为什么是public??
- 如何用java对文本文件进行筛选式修改?具体内容见文章,谢谢!
- 请问在JDK中怎样实现label换行和设置它的长度?
- exception in thread "main" java.lang.NoClassDeffoundError:FindMax/class出现这种错误提示,我错在哪呢?
- 我想学习JAVA,谁能推荐我一本好的入门教材?
- jb5怎样配置可以发布到WEBLOGIC上?
- 在servlet中建立表单显示list的东西让回返回到JSP中。
- 如何编写单进程多协议的程序,同时支持TCP和UDP
- 哪们有关于JNI的电子书或网上资料,能否给我一份
new DataInputStream(
new BufferedInputStream(
new FileInputStream(System.in)));
while ((in.read()) != -1)
{
//dosomething;
}
new DataInputStream(
new BufferedInputStream(System.in));
String s;
try {
while((s = in.readLine()).length() != 0)
System.out.println(s);
// An empty line terminates the program
} catch(IOException e) {
e.printStackTrace();
}
new DataInputStream(
new BufferedInputStream(System.in));
String str = br.readLine();
任何键盘输入数据,都可读出其字符串类型
然后通过转换,得到其他类型
比如
int i = Integer.valueOf(str) ;
注意,都需要捕捉异常,比如输入字符非数字类型等
System.out.print("pls input:");
try{
byte[] b = new byte[10];
System.in.read(b);
String s = new String( b );
System.out.println(s);
int i = Integer.parseInt(s.trim());
System.out.println(i);
}catch(IOException ioe){
ioe.printStackTrace();
}
}
public static void main(String[] args) {
consoleTester consoleTester1 = new consoleTester();
}
}
public class test2{
public static void main(String[] args){
DataInputStream in =
new DataInputStream(
new BufferedInputStream(System.in));
String s;
String a,b;
String s1="Please input integer ";
int i=0;
a="0";
b="0";
System.out.print(s1+" a:");
try {
while((s = in.readLine()).length() != 0){
i=i+1;
if(i==1){ a=s;System.out.print(s1+" b:");}
if(i==2){ b=s;break;}
}
int c=Integer.parseInt(a)+Integer.parseInt(b);
System.out.print("The result of a+b:"+String.valueOf(c));
} catch(Exception e) {
e.printStackTrace();
}
}
}