FileInputStream fis =
new FileInputStream("outdata");
BufferedInputStream bis =
new BufferedInputStream(fis);
DataInputStream dis =
new DataInputStream(bis);
int N = dis.readInt();
for (int i = 1; i <= N; i++) {
int r = dis.readInt();
System.out.println(r);
}
dis.close();
}
catch (IOException e) {
System.err.println(e);
}
}
}
这些程序向文件写入10个整数,然后读出。
获取文件信息
到目前为止,讨论仅涉及对单个文件的输入和输出。但是,还存在加速I/O性能的另一方面,这与查找文件属 性有关。例如,考虑一个打印文件长度的小程序:
import java.io.*;
public class length1 {
public static void main(String args[]) {
if (args.length != 1) {
System.err.println("missing filename");
System.exit(1);
【问题提问、论坛交流】编辑:xker.com

发表评论