一个栈溢出问题
2009-02-16 16:20
197 查看
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package test;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.sql.Blob;
import java.sql.Clob;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author Administrator
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Vector vector = new Vector();
BufferedReader br =null;
try {
br = new BufferedReader(new FileReader(new File("F://Documents and Settings//AVO项目工作//T9_Hor_unInterpolate.xyz")));//一个大约30M的文件,约500000行
} catch (FileNotFoundException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
int i =0;
String line;
try {
while ((line = br.readLine()) != null) {
String[] split = line.split("[//t]+");
//String str = split[0]; //栈溢出
String str = new String(split[0]);
vector.add(str);
System.out.println(i++);
}
} catch (IOException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.lang.String.substring(String.java:1940)
原因:引用传值、拷贝传值。string.split()可能有系列栈操作。
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package test;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.sql.Blob;
import java.sql.Clob;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author Administrator
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Vector vector = new Vector();
BufferedReader br =null;
try {
br = new BufferedReader(new FileReader(new File("F://Documents and Settings//AVO项目工作//T9_Hor_unInterpolate.xyz")));//一个大约30M的文件,约500000行
} catch (FileNotFoundException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
int i =0;
String line;
try {
while ((line = br.readLine()) != null) {
String[] split = line.split("[//t]+");
//String str = split[0]; //栈溢出
String str = new String(split[0]);
vector.add(str);
System.out.println(i++);
}
} catch (IOException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.lang.String.substring(String.java:1940)
原因:引用传值、拷贝传值。string.split()可能有系列栈操作。
相关文章推荐
- 在论坛中出现的比较难的sql问题:16(取一个字段中的数字)
- java 中关于package的一个问题
- NOJ [1015] 一个简单的问题
- 网易面试题之小易是一个数论爱好者,并且对于一个数的奇数约数十分感兴趣。一天小易遇到这样一个问题: 定义函数f(x)为x最大的奇数约数,x为正整数。 例如:f(44) = 11. 现在给出一个N,需要求
- 新手请教一个父窗体和子窗体传值问题
- Exdata cell 节点配置时遇到的一个问题
- 互联网精神,分享------------一个Runas,一个linux字符集的问题
- jsp页面 include 一个静态页面时乱码的问题
- swift override --有一个递归问题未解决
- 一个FileSystemWatcher和线程池的问题
- 问一个关于c的问题
- 一个问过100遍啊100遍的问题
- 记录一个小问题数据库的
- cx_Oracle安装出现的一个问题以及解决办法
- JqueryMobile链接一个页面,而链接页面中图片需刷新才显示的问题
- OpenCV2.2.0版本的更改及源码zip包编译过程中的include路径的一个问题
- DjangoRestFramework的外键反向关系序列化的一个问题
- 今天win 2003服务器上遇到一个问题
- Android中一个动画应用于两个View中不同步的问题