问题
原代码
public static void test21() throws IOException{
FileReader fis = null;
try {
fis = new FileReader("d:/b.txt");
char[] c = new char[1024];
byte[] b = new byte[1024];
int hasRead;
while ((hasRead = fis.read(c)) != -1) {
System.out.println(new String(b, 0, hasRead));
}
} catch (Exception e) {
e.printStackTrace();
} finally {
fis.close();
}
}
new String(b, 0, hasRead)里报错:
String() in String cannot be applied to:
Expected
Parameters:
Actual
Arguments:
c (char[])
0 (int)
hasRead (int)
原因
引入错了String的包,查看import中导入的是
import com.sun.org.apache.xpath.internal.operations.String;
删掉,改用import java.io.*;就可以了。