-2

I'm trying to read a tempdoc.xlsm file when the following line is executed i get a IO error

String fileName = request.getParameter("file");

XSSFWorkbook wb = new XSSFWorkbook();

wb = new XSSFWorkbook(new FileInputStream(fileName)); //error wen executing this line

when i try with the above method i just getting the following message on catch of a IO exception java.io.FileNotFoundException: fileName (The system cannot find the file specified)

can anyone help me with it...

but now i'm getting the followinr exception this isthe stacktrace which is as folllows

SEVERE: Servlet.service() for servlet UploadData threw exception java.lang.OutOfMemoryError: Java heap space at org.apache.xmlbeans.impl.values.NamespaceContext$NamespaceContextStack.(NamespaceContext.java:78) at org.apache.xmlbeans.impl.values.NamespaceContext$NamespaceContextStack.(NamespaceContext.java:75) at org.apache.xmlbeans.impl.values.NamespaceContext.getNamespaceContextStack(NamespaceContext.java:98) at org.apache.xmlbeans.impl.values.NamespaceContext.push(NamespaceContext.java:106) at org.apache.xmlbeans.impl.values.XmlObjectBase.check_dated(XmlObjectBase.java:1273) at org.apache.xmlbeans.impl.values.JavaStringEnumerationHolderEx.enumValue(JavaStringEnumerationHolderEx.java:60) at org.apache.xmlbeans.impl.values.XmlObjectBase.getEnumValue(XmlObjectBase.java:1514) at org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTCellFormulaImpl.getT(Unknown Source) at org.apache.poi.xssf.usermodel.XSSFSheet.onReadCell(XSSFSheet.java:2624) at org.apache.poi.xssf.usermodel.XSSFRow.(XSSFRow.java:72) at org.apache.poi.xssf.usermodel.XSSFSheet.initRows(XSSFSheet.java:178) at org.apache.poi.xssf.usermodel.XSSFSheet.read(XSSFSheet.java:142) at org.apache.poi.xssf.usermodel.XSSFSheet.onDocumentRead(XSSFSheet.java:129) at org.apache.poi.xssf.usermodel.XSSFWorkbook.onDocumentRead(XSSFWorkbook.java:269) at org.apache.poi.POIXMLDocument.load(POIXMLDocument.java:159) at org.apache.poi.xssf.usermodel.XSSFWorkbook.(XSSFWorkbook.java:190) at com.UploadData.doPost(UploadData.java:91) 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 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:852) 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) Exception in thread "ContainerBackgroundProcessor[StandardEngine[Catalina]]" java.lang.OutOfMemoryError: Java heap space

Kartik P
  • 71
  • 1
  • 1
  • 4
  • At first glance, you're trying to open "fileName" and you stated that "tempdoc.xlsm" is what you are looking for. In any case, provide a stack trace and/or more details on the error that is occurring and the community will be better equipped to answer your question. – tschaible Dec 17 '12 at 05:13
  • sorry tempdoc.xlsm is the filename and "filename" contains the path of the file i select i do it this way String fileName = request.getParameter("file"); where file is a parameter passed by my jsp to the java servlet containing the selected file path... wen i try with the above method i just getting the following message on catch of a IO exception java.io.FileNotFoundException: fileName (The system cannot find the file specified) – Kartik P Dec 17 '12 at 05:59

1 Answers1

0

You are using the String literal "fileName" and not the variable fileName.

Try

wb = new XSSFWorkbook(new FileInputStream(fileName)); 

Note that lack of quotes around fileName.

tschaible
  • 7,240
  • 1
  • 26
  • 32
  • hi i have edited the question with the stack trace after the above changes u specified – Kartik P Dec 17 '12 at 06:40
  • Try file you are opening is likely too big for the memory your JVM has allocated. Read through this question, http://stackoverflow.com/questions/37335/how-to-deal-with-java-lang-outofmemoryerror-java-heap-space-error-64mb-heap and adjust the maximum size of the heap to a more appropriate size. – tschaible Dec 17 '12 at 07:26