BufferedReader br=new BufferedReader(InputStreamReader(System.in));
String input=null;
try{
input=br.readLine();
}catch(Exception e){}
这样就可以从命令行读取数据了,不过是字符串类型的。如果你要得到相应的基本数据类型
的话,你可以转化一下,例如:int number=Integer.parseInt(input);
String input=null;
try{
input=br.readLine();
}catch(Exception e){}
这样就可以从命令行读取数据了,不过是字符串类型的。如果你要得到相应的基本数据类型
的话,你可以转化一下,例如:int number=Integer.parseInt(input);
{
public static void main(String args[])throws IOException
{
int i=0;
byte buff[] = new byte[64];
byte bbuff[] = new byte[64];/*模拟的命令行输入*/
bbuff[0]=97;
bbuff[1]=98;
bbuff[2]=99;
/*从命令行读入a*/
int n=System.in.read(buff,0,64);
for(;i<n-2;i++)
{
System.out.println("buff["+i+"]="+buff[i]);
System.out.println("bbuff["+i+"]="+(int)bbuff[i]);
}
System.out.println("n="+n);
String s=new String(buff,0,n-2);
String ss=new String(bbuff,0,n-2);
System.out.println("s="+s);
System.out.println("ss="+ss);
if (s.equals(ss))//原先你s==ss比的是s和ss的地址是否相同
System.out.println("ok");
}
}
否则你那s与ss的字符串用于不会相等了,因为靠输入的s的末两个
字符总是回车换行,而ss你只赋了三个字符,没有回车换行,所以
用于不会相等。以上代码你输入abc,就可以输出ok了。