import java.io.*;public class INSTR
{
public static void main(String[] args) throws IOException
{
byte[] str=new byte[80] ;
int len=System.in.read(str,0,str.length);
String s=new String(str,0,len-2);
System.out.println(s);
}
}
{
public static void main(String[] args) throws IOException
{
byte[] str=new byte[80] ;
int len=System.in.read(str,0,str.length);
String s=new String(str,0,len-2);
System.out.println(s);
}
}
解决方案 »
- unix ,java 专家来看,疑难问题。java 通过Runtime 调用unxi 系统命令的一个小问题
- 怎么在eclipse把数据插入到数据库中
- 正则表达式--》文件上传--》过滤路径取文件名
- Hibernate UUID 的问题
- 新问题,急
- 问StringBuffer在方法中改变,但输出为什么没变?
- 请问,swing中的控件可以是任意形状的吗?比如,斜线
- 到底java有几种
- Eclipse 帮助窗口问题求助
- 在执行 rs.previous(); 的时候,出现的错误
- 大家好,有谁知道自己做的javabean在TOMCAT怎么配置吗?比如我的虚拟目录是d:\myjsp,并且已配好,可是就是不知道自己做的bean在server.x
- 如何用java在硬盘上创建一个word文件?
str1是数组,str是字符变量
public class ReadFromKB
{
public static void main(String args[])
{
try{
byte bArray[]=new byte[40];
String str;
System.out.println("Enter something Using Keyborad:");
int c=System.in.read(bArray);;
System.out.println(c);
str = new String(bArray, 0);
System.out.print("You entered:");
System.out.println(str);
}
catch(IOException ioe)
{
System.out.println("Error!");
}
}
}
可以实现吗?向各位学习ing……
import java.io.*;public class INSTR
{
public static void main(String[] args) throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str=br.readLine();
System.out.println(str);
}
}
当我输入123456789
为什么len=11呢
我是新手请大家多多指教
所以构造String时,用了len-2,不过不减也无所谓,也能得到正确结果,只是
会多出回车换行两个字符。
(以命令行参数为例)
char[] s=args[0].toCharArray();
//将args[0]的字符串变成字符数组