0

我正在使用 Windows 系统执行下面提到的 java 代码。它工作正常,没有任何错误。但我尝试在 Linux 环境中执行此代码,但出现“ java.lang.reflect.InvocationTargetException ”错误。

        String status = "Initialized!";
    try
    {
        String rootPath = "C:/FolderA.1/FolderA1.1.1/FolderA1.1.1A/"; /**Windows**/
        String rootPath = "/opt/FolderA/FolderA.1/FolderA1.1.1/FolderA1.1.1A/"; /**Linux**/
        
        String reportFileLocation = rootPath + File.separator + fileName;
        FileInputStream excelFile = new FileInputStream(new File(reportFileLocation));
        XSSFWorkbook workbook = new XSSFWorkbook((InputStream)excelFile);
        {
            XSSFSheet reportSheet = workbook.getSheet("Report");
            XSSFSheet formatSheet = workbook.getSheet("Format");
            if(reportSheet == null)
            {
                workbook.close();
                throw new Exception("Sheet name \"Report\" is not available! Please add \"Report\" sheet!");
            }
            if(formatSheet == null)
            {
                workbook.close();
                throw new Exception("Sheet name \"Format\" is not available! Please add \"Format\" sheet!");
            }
            /** Delete other sheets **/
            int sheetsCount = workbook.getNumberOfSheets();
            int s = 0;
            for( ;s < sheetsCount; s++)
            {
                String sheetName = workbook.getSheetName(s);
                if(sheetName.equals("Report") || sheetName.equals("Format"))
                {
                    
                }
                else
                {
                    workbook.removeSheetAt(s);
                    sheetsCount--;
                    s--;
                }
            }
        }
        FileOutputStream outputStream = new FileOutputStream(reportFileLocation);
        workbook.getCreationHelper().createFormulaEvaluator().evaluateAll();
        workbook.write((OutputStream)outputStream);
        workbook.close();
        status = "OK";
    }
    catch(Exception err)
    {
        status = err.getMessage();
    }

如何解决这个问题?

4

1 回答 1

0

感谢@Gagravarr 的回复。

得到带有以下代码的确切错误消息并已解决。

try
{
  //my logic
}
catch(Exception err)
{
    status = err.getMessage();
    status = status + err.getCause();
}
于 2020-08-18T04:24:22.040 回答