java程序上传一个文件的时候出现了这个问题,希望大家可以帮下忙

水里游 发布于 2013/07/26 10:12
阅读 294
收藏 0
java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:270)
	at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:187)
	at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
	at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
	at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
	at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at com.tom.filter.EncodingFilter.doFilter(EncodingFilter.java:81)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
	at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.OutOfMemoryError: Java heap space
加载中
0
子木007
子木007
Caused by: java.lang.OutOfMemoryError: Java heap space

文件太大了吧
子木007
子木007
回复 @水里游 : 简单的就是加大内存, -Xmx
水里游
水里游
嗨,又是你啊,上次有个问题也是你哦。嗯,我知道是文件太大,但是怎么可以解决呢?
0
水里游
水里游
这是上传文件的代码,是Struts1的框架
UpfileForm upfileForm = (UpfileForm) form;
		FormFile file = upfileForm.getFile();
		FileOutputStream fileOutput;
		// 如果文件夹不存在就创建一个
		if (file != null) {
			try {
				File file1 = new File(getServlet().getServletContext()
						.getRealPath("\\upload"));
				if (!file1.exists()) {
					file1.mkdir();
					File file_swf = new File(getServlet().getServletContext()
							.getRealPath("\\upload\\swf"));
					if (!file_swf.exists()) {
						file_swf.mkdir();
					}
				}
                fileOutput = new FileOutputStream(getServlet()
						.getServletContext().getRealPath("\\upload\\")
						+ "\\" + file.getFileName());
				fileOutput.write(file.getFileData());
				fileOutput.flush();
				fileOutput.close();
水里游
水里游
我试一下,新手希望别介意。有很多东西不懂。
子木007
子木007
刚看了一下api, 应该用 file.getInputStream()
子木007
子木007
从你的代码看,有些不妥,file.getFileData() 猜测应该是把整个文件都读到内存了, 一个巨大无比的 byte[] 吃掉了内存。 应该采用 stream 的方式写文件。
返回顶部
顶部