关于java控制台的初级程序的一个问题?

来源:百度知道 编辑:UC知道 时间:2024/06/24 08:18:56
VS2003下的J#,遇到一个问题如下:
char c = 0;
try
{
c = (char)System.in.read();
}catch(IOException e){};
System.out.println("You've entered character: "+c);

String s = "";
try
{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
s = in.readLine();
}catch(IOException e){}
System.out.println("You've entered string: "+s);

第一个问题:不知道是什么原因,第二段代码无法阻塞,也就是无法提示输入数据。
第二个问题:是不是System.in.必段放在try catch代码段中才可以?

多谢~
以前都用C++的,才刚看了一点点java。但是我不放在try当中,它就是提示有错误啊。

import java.io.*;
public class Read{
public static void main(String[] args){
char c = 0;
try
{
c = (char)System.in.read();
while(System.in.read()!=10);
}catch(IOException e){};
System.out.println("You've entered character: "+c);

String s = "";
try
{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
s = in.readLine();
}catch(IOException e){}
System.out.println("You've entered string: "+s);
}
}

不是system.in要放在里面,而是读写文件有异常