import java.io.*;
public class Test {
public static void main(String[] args) throws IOException{
String operate="";
String object="";
char[] chop=new char[10];
char[] chob=new char[100];
int i=0;
System.out.println("Please input the operate:");
while(i<10){
chop[i]=(char)System.in.read();
if(chop[i]=='\n'||chop[i]=='\r') break;
}
operate=new String(chop);
System.out.println(operate);
i=0;
System.out.println("Please input the name:"); //只能运行到这里
while(i<100){
chob[i]=(char)System.in.read();
if(chob[i]=='\n'||chob[i]=='\r') break;
}
object=new String(chob);
System.out.println(object);
}
}还有,请教一下,有没有什么方法,读取在命令行输入的字符串,我不想用readline,我希望实现的是:比如,命令行输入 mkdir abc,把个当作两个String存入~小弟刚刚学,有不对的请各位大虾多多指教,谢谢了!
public class Test {
public static void main(String[] args) throws IOException{
String operate="";
String object="";
char[] chop=new char[10];
char[] chob=new char[100];
int i=0;
System.out.println("Please input the operate:");
while(i<10){
chop[i]=(char)System.in.read();
if(chop[i]=='\n'||chop[i]=='\r') break;
}
operate=new String(chop);
System.out.println(operate);
i=0;
System.out.println("Please input the name:"); //只能运行到这里
while(i<100){
chob[i]=(char)System.in.read();
if(chob[i]=='\n'||chob[i]=='\r') break;
}
object=new String(chob);
System.out.println(object);
}
}还有,请教一下,有没有什么方法,读取在命令行输入的字符串,我不想用readline,我希望实现的是:比如,命令行输入 mkdir abc,把个当作两个String存入~小弟刚刚学,有不对的请各位大虾多多指教,谢谢了!
类 StringTokenizer
java.lang.Object
-java.util.StringTokenizer
下面是一个使用 tokenizer 的实例。代码如下: StringTokenizer st = new StringTokenizer("this is a test");
while (st.hasMoreTokens()) {
System.out.println(st.nextToken());
}
输出以下字符串: this
is
a
test
这时缓冲区中还有'\r'
这个使得第二个:chop[i]=='\n'||chop[i]=='\r'直接退出了