不会的,RandomAccessFile对于过大文件,不会一次性全部读出,而是一次一小段。我这里读取365M的大文件,内存占用也只有51KB
//------------------------ import help.Functions; import java.io.RandomAccessFile; public class A { public static void main(String[] args) { try { long start = Runtime.getRuntime().freeMemory(); RandomAccessFile rF = new RandomAccessFile( "D:/cxz/压缩软件/S60-SDK-200634-3.1-Cpp-f.1090b.zip ", "r "); for (int i = 0; i < 100; i++) { if ((i % 16) == 0) System.out.print( "\r\n "); System.out.print(Functions.getByteHexStr(rF.readByte()) + " "); } long end = Runtime.getRuntime().freeMemory(); System.out.println( "\n\nused menory: " + (start - end) / 1024 + "KB "); rF.close(); } catch (Exception e) { e.printStackTrace(); } } } |
|