readfile.java
来自「基于网络编程的例子」· Java 代码 · 共 30 行
JAVA
30 行
// File: ReadFile.java
//
// Example of saving Java objects to a compressed data file
//
import java.io.*;
import java.util.zip.*;
public class ReadFile {
static public void main(String [] args) {
String file_name = "car.data";
Car c1, c2;
// Always wrap file IO in a try/catch statement:
try {
FileInputStream f = new FileInputStream(file_name);
GZIPInputStream gf = new GZIPInputStream(f);
ObjectInputStream ois = new ObjectInputStream(gf);
c1 = (Car)ois.readObject();
c2 = (Car)ois.readObject();
ois.close();
System.out.println("Cars reads from file: " + c1.getName() +
" and " + c2.getName());
} catch (Exception e) {
System.out.println("Error: " + e);
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?