【问题标题】:Why simple FileInputStream line return exception?为什么简单的 FileInputStream 行返回异常?
【发布时间】:2014-08-20 13:44:48
【问题描述】:

按钮操作;

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
  try {
  // TODO add your handling code here:
     deneme();
    } catch (IOException ex) {
       Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
  }
}  

文件读取无效;

public void deneme() throws FileNotFoundException, IOException{
    try {
            FileInputStream file2 = FileInputStream (new File("D:\\Ornek.xls"));
            HSSFWorkbook workbook;
            workbook = new HSSFWorkbook(file2);
            HSSFSheet sheet = workbook.getSheetAt(0);
            HSSFRow row1 = sheet.getRow(0);
            HSSFCell cellA1 = row1.getCell((short) 0);
            String a1Val = cellA1.getStringCellValue();
            HSSFCell cellB1 = row1.getCell((short) 1);
            String b1Val = cellB1.getStringCellValue();
            HSSFCell cellC1 = row1.getCell((short) 2);
            String c1Val = cellC1.getStringCellValue();;

            System.out.println("A1: " + a1Val);
            System.out.println("B1: " + b1Val);
            System.out.println("C1: " + c1Val);
                }
            catch (IOException ex) {
                    Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null,ex);
                }


}

调试时出现以下异常;

Exception in thread "AWT-EventQueue-0" java.lang.UnsupportedOperationException: Not supported yet.

FileInputStream 行抛出异常。我错过了什么吗?

谢谢。

-- 已解决--

对不起,首先提出愚蠢的问题:)

FileInputStream file2 = new FileInputStream (new File("D:\\Ornek.xls"));

new 开头缺少关键字。感谢@dkatzel

【问题讨论】:

标签: java apache-poi fileinputstream


【解决方案1】:

我认为您缺少 new 关键字。

试试这个:

FileInputStream file2 = new FileInputStream (new File("D:\\Ornek.xls"));

但这应该是编译错误而不是运行时错误。

【讨论】:

  • 啊,你是对的:(奇怪的是我没有在线编译错误。应用程序工作但转异常。
猜你喜欢
  • 2019-09-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-08
  • 2012-03-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多