为什么我不能在类中声明BufferedReader并在方法上使用它的对象?

时间:2017-02-20 19:49:21

标签: object static instance bufferedreader ioexception

public class Example {
    static String s;
    static String str;
    static String[] strArray;
    static BufferedReader br = new BufferedReader(new FileReader("C:........."));
    ...
}

IDE提供的错误:

  

默认构造函数无法处理异常类型FileNotFoundException   由隐式构造函数抛出。方法必须定义显式   构造

public static void main(String[] args) throws IOException {
    method1();
}

public void method1()throws IOException {
    str = br.readLine(); // I want to be able to use the br object here
                         // or any method as per need.
    strArray = str.split("//s");
    for(String s: strArray) {
        Sysout.out.println(s);
    }
}

0 个答案:

没有答案