作者god800606 (还没想到)
看板java
标题[问题] 关於读大文字档的OutOfMemoryError
时间Thu Jul 21 16:25:28 2011
大家好~
小弟因为打工需要
算是刚接触JAVA不久
基本上都是一直参考CODE来学习
最近要写一个处理很大纯文字档的tool
档案大约快200Mb
目前能做到的 单纯read的话大约能读70~80M
想说之後seperate剪接处理应该能做到200M
不过用swing做出来之後 大约15M的档案就会出现
OutOfMemoryError
有爬过文 用-Xmx去改JVM default设置可以成功
可是如果这个tool 用exej4转exe後
给其他台电脑用 是不是也要去改呢?
所以想改一下演算法
不过不知道该从哪部分下手
可否请各位大大帮忙看一下
拜托了
public static void read2array(File file) throws Exception {
InputStream in = null;
long t_i,t_f = 0;
try{
in = new BufferedInputStream(new FileInputStream(file));
int bufLen = 20000*1024;
byte[] buf = new byte[bufLen];
byte[] tmp = null;
int len = 0;
String strFileContents;
t_i = System.currentTimeMillis();
while((len = in.read(buf,0,bufLen)) != -1){
// extend array
tmp = new byte[out.length + len];
// copy data
System.arraycopy(out,0,tmp,0,out.length);
System.arraycopy(buf,0,tmp,out.length,len);
out = tmp;
tmp = null;
strFileContents = new String(out, 0, len);
textArea.append(strFileContents);
}
}finally{
// always close the stream
if (in != null)
try{
in.close();
t_f = System.currentTimeMillis()-t_i;
System.out.println(t_f);
}catch (Exception e){
JOptionPane.showMessageDialog(null, e.toString(),
"开启档案失败", JOptionPane.ERROR_MESSAGE); }
}
}
ps上面是有参考有人写的 bigfilereader
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 211.23.86.187
1F:→ james732:你要做的处理是什麽?能不能读一点做一点? 07/21 16:31
2F:→ god800606:嗯嗯 处理档案是没问题的 是要把还没处理的档案显示在 07/21 16:41
3F:→ god800606:Jtextarea 区域时 才会出现 outofmemory error 07/21 16:43
4F:→ dou0228:请自己做 paging(分页) 不要一次全载入 07/21 18:22
5F:→ god800606:好~ 谢谢D大 我会试试看~ 07/21 21:07
6F:→ god800606:我有试着做paging 不还是会出现 outofMemoryerror QQ 07/25 14:58
7F:→ dou0228:先贴 code 上来看一下你 paging + JTextArea 怎麽写的 07/25 15:14