您的位置:首页 > 其它

一个栈溢出问题

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()可能有系列栈操作。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: