0
基本上,我有这样的代码来解压缩一些字符串,在一个文件存储:的Java NIO和的FileInputStream
public static String decompressRawText(File inFile) {
InputStream in = null;
InputStreamReader isr = null;
StringBuilder sb = new StringBuilder(STRING_SIZE);
try {
in = new FileInputStream(inFile);
in = new BufferedInputStream(in, BUFFER_SIZE);
in = new GZIPInputStream(in, BUFFER_SIZE);
isr = new InputStreamReader(in);
int length = 0;
while ((length = isr.read(cbuf)) != -1) {
sb.append(cbuf, 0, length);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
in.close();
} catch (Exception e1) {
e1.printStackTrace();
}
}
return sb.toString();
}
由于物理IO是相当耗费时间,而且由于我的压缩文件的版本都相当小(约2K从2M的文本),是否有可能仍然执行上述操作,但在已映射到内存的文件上?可能使用java的NIO?谢谢