java read需要import
时间: 2023-05-27 22:03:31 浏览: 61
java学习-java中的import
java.io.InputStream 和java.io.InputStreamReader类,具体代码如下:
```java
import java.io.*;
public class Main {
public static void main(String[] args) {
try {
InputStream is = new FileInputStream("file.txt");
InputStreamReader isr = new InputStreamReader(is);
int c;
while ((c = isr.read()) != -1) {
System.out.print((char)c);
}
isr.close();
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
```
阅读全文