OS描述一份文件需要两类信息:
1、元信息
2、内容数据
Java中使用哪个类来描述文件元信息——文件?File
演示相对路径,相对于什么?相对于启动程序(变成进程时)所在的路径
不是静态意义上的相对,不能看代码结构是怎么样,而是需要看运行的那一刻的路径。
IDEA是可以配置这个路径。
import java.io.*;
public class FileInputStreamDemo {
public static void main(String[] args) throws IOException {
InputStream is = new FileInputStream(“用于读的文件.txt”);
byte[] buf = new byte[8192];
int len;
while ((len = is.read(buf)) != -1) { // new byte[2] len = 2, 2, 1, -1
// new byte[3] len = 3, 2, -1
System.out.println(“读一次”);
for (int i = 0; i < len; i++) {
System.out.println(buf[i]);
}
}
is.close();
}
}
Input和Output
最新推荐文章于 2022-11-04 16:47:04 发布