2016-07-28 72 views
-1

当我试图通过java程序访问excel文件时,我收到异常java.io.FileNotFoundException: D:\Selenium Reports\Daily Reports\Merged file.xls通过FileInputStream()执行excel文件的java.io.FileNotFoundException

我曾尝试用:

  1. 绝对路径
  2. 相对路径
  3. 读/写文件
  4. 检查文件是否打开

仍然可以访问,它没有工作,是不是工作,因为我有访客访问机器?

+1

你最好提供代码。 – Gearon

+0

你正在使用什么构建工具和IDE? –

+0

'FileNotFoundException'表示无法找到该文件。真的没有什么可以说的。 – ifly6

回答

0

保持的.java文件和的.xls文件在同一个文件夹中,并使用代码:

try { 
     File f = new File("Merged file.xls"); 
     if (!f.exists()) { 
      System.out.println("File does not exist"); 
      if (!f.createNewFile()) 
       System.out.println("File cannot be created"); 
      else 
       System.out.println("File created"); 
     } else { 
      System.out.println("File exists"); 
      if(!f.canRead()) 
       System.out.println("Error in reading. Need permission"); 
      if(!f.canWrite()) 
       System.out.println("Error in writing. Need permission"); 
     } 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 
} 
+0

感谢Geet的努力。 –

+0

欢迎,但它工作? –

+0

是的,它为我工作。 –