java.lang.outofmemory 异常 jvm 堆大小不足
我试图读取一个只有一行的文本文件。文件大小超过 50Mb。当我尝试使用以下代码读取它时,它给出了
java.lang.outofmemory异常jvm 堆大小不足
我将java堆内存更改为1GB。但它仍然给出了同样的例外。
设置JAVA_OPTS=-Xms1024m -Xmx1024m
我使用下面的代码片段来读取文件。
BufferedReader Filein1=new BufferedReader(新FileReader(新 文件(“C:\ABC\MsgStream.txt”))); s=Filein1.readLine();
有人可以告诉我如何克服这个问题吗?提前致谢。
I tried to read a text file which have only one line. File size is over 50Mb. When I tried to read it using the following code it gives
java.lang.outofmemory exception jvm
heap size insufficient
I change the java heap memory to 1GB . But still it gives the same exception.
set JAVA_OPTS=-Xms1024m -Xmx1024m
I use foollowing code pragment to read the file.
BufferedReader Filein1=new
BufferedReader(new FileReader( new
File( "C:\ABC\MsgStream.txt" )));
s=Filein1.readLine();
Can some one please tell me how to overcome this problem. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
JAVA_OPTS 环境变量仅受到某些应用程序的尊重(例如通常用于启动 Tomcat 的包装器脚本)。
java
命令不关心它。您需要将选项放在
java
命令行上...类名之前;例如(1Gb 堆对于缓冲 50Mb 文件应该绰绰有余。)
The JAVA_OPTS environment variable is only respected by certain applications (for example the wrapper scripts that are typically used to launch Tomcat). The
java
command doesn't pay any attention to it.You need to put the options on the
java
command line ... before the classname; e.g.(A 1Gb heap should be more than adequate for buffering a 50Mb file.)
JAVA_OPTS 实际上在输出中运行吗?您可能需要实际将它们放在正在运行的命令行上,或者在其中包含 $JAVA_OPTS 。
Are JAVA_OPTS actually being run in the output? You may need to actually put them on the command line you're running, or include $JAVA_OPTS on it.
这是 _JAVA_OPTIONS 不是 JAVA_OPTS
如果你有这样的课程
,那么你应该得到
It's _JAVA_OPTIONS not JAVA_OPTS
If you have a class like
then you should get