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?謝謝