首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

写大文件内存溢出的有关问题

2011-12-11 
写大文件内存溢出的问题如题,怎样写出一个100M左右的文件,而不溢出内存?[解决办法]用bufferredreader会溢

写大文件内存溢出的问题
如题,
怎样写出一个100M左右的文件,而不溢出内存?

[解决办法]
用bufferredreader会溢出吗?楼主试试。
[解决办法]
long length=0xffffff;
String file = "G:\\a.dat ";
MappedByteBuffer out = new RandomAccessFile(file, "r ")
.getChannel().map(FileChannel.MapMode.READ_ONLY, 0, length);
for (int i = 0; i < length; i++)
out.put((byte) 'x ');
System.out.println( "Finished writing ");
for (int i = 0; i < 10; i++)
System.out.println((char) out.get(i)); // read file
[解决办法]
MappedByteBuffer out = new RandomAccessFile(file, "r ")
.getChannel().map(FileChannel.MapMode.READ_WRITE, 0, length);
[解决办法]
up
[解决办法]
帮顶~
[解决办法]
public class LargeFile {

public static void main(String[] args) throws Exception ...{
long length = 0x8ffffff;
MappedByteBuffer out = new RandomAccessFile( "G:\a.dat ", "rw ").getChannel()
.map(FileChannel.MapMode.READ_WRITE, 0, length);
for (int i = 0; i < length; i++)
out.put((byte) 'x ');
System.out.println( "Finished writing ");
for (int i = 0; i < 10; i++)
System.out.println((char) out.get(i)); // read file
}
}
[解决办法]
如果文件太大,最好边读边写
[解决办法]
flush 不行吗?
[解决办法]
100M也溢出?

热点排行