【发布时间】:2011-08-25 20:18:45
【问题描述】:
我有许多压缩字符串(每个 1.5M)存储在一个文件中。我需要把它们读出来,并对它们做一些计算。基本上,这就是我所做的:
public static Object fetchRSFB(File inFile) {
FileInputStream fis = null;
ObjectInputStream ois = null;
GZIPInputStream gs = null;
Object result = null;
try {
fis = new FileInputStream(inFile);
gs = new GZIPInputStream(fis);
ois = new ObjectInputStream(gs);
MyBWT.rankArray = (int[]) ois.readObject();
String str= (String) ois.readObject();
//do something with the string
唯一的问题是,代码的性能总体上很慢,所以我在考虑2个选项:
-
使用NIO将压缩文件映射到内存中,对内存压缩文件进行上述操作(听说可以实现,不知道是不是真的)
我可以不存储对象,只存储文本的二进制压缩版本,然后读取文本,听说可能比 ObjectInputStream 快。
有人知道实现上述选项的方法吗?或者有没有更好的方法,非常感谢。
【问题讨论】:
标签: android performance text io nio