Java中BufferedReader的read方法问题
有一个read方法定义publicintread(char[]cbuf,intoff,intlen)我写了下面这个类测试publicclasstest3{publics...
有一个read方法定义public int read(char[] cbuf,int off,int len)
我写了下面这个类测试
public class test3 {
public static void main(String[] args) {
try {
FileReader fw = new FileReader("C:\\a.txt");
BufferedReader bw = new BufferedReader(fw);
char[] cbuf = null;
bw.read(cbuf,0,4);
fw.close();
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
结果报错:
Exception in thread "main" java.lang.NullPointerException
at java.io.BufferedReader.read(BufferedReader.java:254)
at test.test3.main(test3.java:19)
请高手解决 展开
我写了下面这个类测试
public class test3 {
public static void main(String[] args) {
try {
FileReader fw = new FileReader("C:\\a.txt");
BufferedReader bw = new BufferedReader(fw);
char[] cbuf = null;
bw.read(cbuf,0,4);
fw.close();
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
结果报错:
Exception in thread "main" java.lang.NullPointerException
at java.io.BufferedReader.read(BufferedReader.java:254)
at test.test3.main(test3.java:19)
请高手解决 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询