io问题? 本帖最后由 remo866 于 2012-07-10 14:35:07 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 try { //如果try语句块里捕获到异常,就直接跳过try语句里最后一句的return line,所以就一直//停在System.out.println("str"+str);这里 bufr = new BufferedReader(new InputStreamReader(System.in)); bufw = new BufferedWriter(new OutputStreamWriter(System.out)); //String line = null; if((line=bufr.readLine())!=null) { bufw.write(line,0,line.length()); bufw.newLine(); bufw.flush(); } return line; } catch (IOException e) { throw new RuntimeException("读写失败"); } finally { try { if(bufr!=null) bufr.close(); } catch (IOException e) { throw new RuntimeException("读取流关闭失败"); } try { if(bufw!=null) bufw.close(); } catch (IOException e) { throw new RuntimeException("写入流关闭失败"); } }建议楼主在这里遇到异常就马上停止程序 没有遇到异常,我设置断点看了的。实际上我查看main方法里面变量变量都能看到值,但不会是sop语句错了吧。是什么原因呢?这个inputStr方法也能返回 把inputStr方法改成 public static String inputStr() { Scanner input = new Scanner(System.in); String str = input.next(); return str; } 如果说inputStr方法也能返回那你试试String str = ""; //将str = null, 改成str = ""试试 System.out.println("请输入英文字符串"); str = inputStr();//从键盘输入字符串 System.out.println("str"+str);// 程序在这里结束了?调试也没找到原因 找到答案了 ,finally的代码关闭了in,out流导致。谢谢热心的朋友。 《Java方法重写问题》想到的 模式识别求助!!! 怎样创建java程序 一个接口的基础问题 如何得到键盘焦点,急!!!!! 调查:毕业一年的Java程序员,你们这一年都做过几个项目,学到了什么,打算学习什么,向什么方向发展? 请高手相助,如何提高向远程sqlserver的插入速度 初学者 编译问题 100 分求救JAVA基础问题,在线等。。 jmf求助 JAVA泛型的类型形参可以设置下限吗??
try
{ //如果try语句块里捕获到异常,就直接跳过try语句里最后一句的return line,所以就一直
//停在System.out.println("str"+str);这里
bufr = new BufferedReader(new InputStreamReader(System.in));
bufw = new BufferedWriter(new OutputStreamWriter(System.out));
//String line = null; if((line=bufr.readLine())!=null)
{
bufw.write(line,0,line.length());
bufw.newLine();
bufw.flush();
}
return line; }
catch (IOException e)
{
throw new RuntimeException("读写失败");
}
finally
{
try
{
if(bufr!=null)
bufr.close();
}
catch (IOException e)
{
throw new RuntimeException("读取流关闭失败");
}
try
{
if(bufw!=null)
bufw.close();
}
catch (IOException e)
{
throw new RuntimeException("写入流关闭失败");
}
}建议楼主在这里遇到异常就马上停止程序
{
Scanner input = new Scanner(System.in);
String str = input.next();
return str;
}
那你试试String str = ""; //将str = null, 改成str = ""试试
System.out.println("请输入英文字符串");
str = inputStr();//从键盘输入字符串
System.out.println("str"+str);// 程序在这里结束了?调试也没找到原因