控制台读入字符串 System.in.read()试过了,不行啊!还有办法吗?或者可以给我一个例子吗? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 //由用户输入字符串 int b=-1; byte buffer[]=new byte[1024]; b = System.in.read(buffer); String strInput = new String(buffer,0,b-2); System.in.close(); //将字符串转换为字符数组 char[] charInput = strInput.toCharArray(); import java.io.*;class BRRead{ public static void main(String arg[]) throws IOException { char c; BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter characters,'q' to quit."); //read characters do{ c=(char)br.read(); System.out.println(c) ; }while(c!='q'); }} 最简单的使用System.in.read(byte[],int,int)就可以搞定,不过可能不能满足你的要求,象这样byte[] input=new byte[10];System.int.read(input,0,input.length);System.out.println(new String(input));如果你输入的字符串长度大于input的长度,那么后面的将被截掉 谢谢各位的帮助,采用的hehecafe的办法解决了问题,但是zhjjava对我也有帮助,由于原来问题给的分值就少,所以只能这样给分了 求jdbc 封装及存储 请问各们达人一个关于树拖动的错误:Drag and drop in progress 找不到符号 有关编码和InputStream类两个问题 局部程序内变量与局部程序块外变量的疑问 可以为java桌面应用程序设置系统的快捷键吗? 一个简单的问题,很急,在线求助:我要把一个数组用传引用的方式,传给一个函数,怎么做?而且,如果一个数组我也不晓得会有多少元素在里 JDK好像很慢,什么原因? 怎样禁止JToolbar被用户拖动? 整型数据做函数的参数,怎样实现传地址,和调用程序共用一个地址? 如何在java中引用多个接口呢(在线加分) 什么叫“藏着手臂的维纳斯”?
int b=-1;
byte buffer[]=new byte[1024];
b = System.in.read(buffer);
String strInput = new String(buffer,0,b-2);
System.in.close(); //将字符串转换为字符数组
char[] charInput = strInput.toCharArray();
class BRRead{
public static void main(String arg[])
throws IOException
{
char c;
BufferedReader br=new
BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter characters,'q' to quit.");
//read characters
do{
c=(char)br.read();
System.out.println(c) ;
}while(c!='q');
}
}
System.int.read(input,0,input.length);
System.out.println(new String(input));如果你输入的字符串长度大于input的长度,那么后面的将被截掉