现在我的程序在纯windows下没有问题,但是当部署到linux环境就读不出来Excel文件了。
大致的意思:客户在windows环境下,选择excel进行数据导入(程序部署在linux环境下)。请高手帮帮忙!!!!是不是还要判断是属于windows环境和linux环境啊?????代码如下:
try
InputStream fis = null;
HSSFWorkbook workbook = null;
String fileName = (String) this.getContext().getParam("fileName");//从本地选择Excel文件
//String s = System.getProperty("file.separator");
fis = new FileInputStream(fileName);
workbook = new HSSFWorkbook(fis);
fis.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(fis != null){
try {
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
大致的意思:客户在windows环境下,选择excel进行数据导入(程序部署在linux环境下)。请高手帮帮忙!!!!是不是还要判断是属于windows环境和linux环境啊?????代码如下:
try
InputStream fis = null;
HSSFWorkbook workbook = null;
String fileName = (String) this.getContext().getParam("fileName");//从本地选择Excel文件
//String s = System.getProperty("file.separator");
fis = new FileInputStream(fileName);
workbook = new HSSFWorkbook(fis);
fis.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(fis != null){
try {
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
这句话的作用是得到所选择的Excel文件。this.getContext().getParam()是我公司写的,是没有问题的。
excel文件用java读取和 是不是windows没关系,如果所有代码都在windows下正常运行的话,那么你可以从下面几个方向找原因:1。 最有可能的就是文件路径问题,一定要确定文件路径及文件在换成linux之后还是正确的,可以输出一下看一下是不是获取到了file,然后看一下file的路径是不是正确的,这也是最大的可能了。2。 是不是jdk版本问题,换了环境,看一下jdk版本等相关是不是和win下面一样3。 继续检查代码,如果windows下面没问题的话,这个几乎也没什么问题,关键还是在 是不是路径正确。
假设我选择windows下的桌面上的Template.xls文件
打出来的日志
java.io.FileNotFoundException: /C:\Documents and Settings\issuser\Desktop\Template.xls (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at java.io.FileInputStream.<init>(FileInputStream.java:66)
at com.iss.qct.hgz.information.HgzInfoOperate.getHSSFWorkbook(HgzInfoOperate.java:429)
at com.iss.qct.hgz.information.HgzInfoOperate.documentImport(HgzInfoOperate.java:454)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.toft.core2.service.ServiceManager.callService(Unknown Source)
at com.toft.core2.proxy.proxyutils.ProxyUtilsForJava.invoke(Unknown Source)
at com.toft.core2.proxy.proxyutils.ProxyUtilsManager.invoke(Unknown Source)
at com.toft.core2.proxy.AbstractProxy.callService(Unknown Source)
at com.toft.core2.proxy.ProxyManager.callServiceProxy(Unknown Source)
at com.toft.core2.action.CoreAction.callServiceProxy(Unknown Source)
at com.iss.qct.hgz.information.HgzInfoAction$$EnhancerByCGLIB$$7cc831a3.CGLIB$callServiceProxy$14(<generated>)
at com.iss.qct.hgz.information.HgzInfoAction$$EnhancerByCGLIB$$7cc831a3$$FastClassByCGLIB$$f4346feb.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:167)
at sun.reflect.GeneratedMethodAccessor70.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.toft.core2.mvc.proxy.AopProxy.intercept(Unknown Source)
at com.iss.qct.hgz.information.HgzInfoAction$$EnhancerByCGLIB$$7cc831a3.callServiceProxy(<generated>)
at com.iss.qct.hgz.information.HgzInfoAction.documentImport(HgzInfoAction.java:122)
at com.iss.qct.hgz.information.HgzInfoAction$$EnhancerByCGLIB$$7cc831a3.CGLIB$documentImport$7(<generated>)
at com.iss.qct.hgz.information.HgzInfoAction$$EnhancerByCGLIB$$7cc831a3$$FastClassByCGLIB$$f4346feb.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:167)
at sun.reflect.GeneratedMethodAccessor70.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.toft.core2.action.BusLogInterceptor.invoke(Unknown Source)
at sun.reflect.GeneratedMethodAccessor72.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.toft.core2.mvc.proxy.ProxyInvocation.invoke(ProxyInvocation.java:60)
at com.toft.core2.action.ActionInterceptor.doIntercept(Unknown Source)
at com.toft.core2.mvc.proxy.MethodFilterInterceptor.invoke(Unknown Source)
at sun.reflect.GeneratedMethodAccessor72.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.toft.core2.action.ExceptionInterceptor.invoke(ExceptionInterceptor.java:56)
at sun.reflect.GeneratedMethodAccessor72.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.toft.core2.mvc.proxy.AopProxy.intercept(Unknown Source)
at com.iss.qct.hgz.information.HgzInfoAction$$EnhancerByCGLIB$$7cc831a3.documentImport(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.toft.core2.mvc.ToftMvcFactory.serviceAction(ToftMvcFactory.java:160)
at com.toft.core2.mvc.ToftFilter.doFilter(ToftFilter.java:106)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:873)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
at java.lang.Thread.run(Thread.java:619)
一个英文的,一个翻译的:
http://apicode.gicp.net/class.do?api=selectByfatherIndex&father=255
http://apicodecn.gicp.net/class.do?api=selectByfatherIndex&father=255
C:\Documents and Settings\issuser\Desktop\Template.xls
把文件路径修改一下如 /home/test/test.xls
POI读取文件应该跟操作系统没有关系。
很明显是路径问题, 你把 new file的那一块代码改一下,把 C:\Documents and Settings\issuser\Desktop\ 这个串改成 你在linux下的 xls文件所在路径就完事了