日期:2014-05-20 浏览次数:20725 次
package com.com.com; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class IoStream { public static InputStreamReader in = new InputStreamReader(System.in); public static BufferedReader br = new BufferedReader(in); /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { // TODO Auto-generated method stub String str = br.readLine(); System.out.println(str); } }
------解决方案--------------------
public static InputStreamReader in = new InputStreamReader(System.in); //这个分号不对
另外, br.readLine(); 可能会抛出异常,要做异常捕捉处理或者继续往上抛出异常,所以,可以修改为
try { String str = br.readLine(); System.out.println(str); } catch (Exception e) { e.printStackTrace(); }
------解决方案--------------------
public static InputStreamReader in = new InputStreamReader(System.in); public static BufferedReader br = new BufferedReader(in); public static void main(String[] args) { // TODO Auto-generated method stub String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } System.out.println(str); }