尝试嵌套资源的Java

时间:2019-01-03 04:39:46

标签: try-catch

尝试嵌套资源时出现错误

我使用了try catch块,并且我正在finally块中关闭资源。

File contentOutputFileName;
            File outDirectory ;
            try
            {
                byte[] bytes = outputStream.toByteArray();
                String directory = versionNumber.substring(0,6);
                String dir = versionNumber.substring(0,8);
                String outputDirectory = outputLocation+ reportId +"//"+ directory+"//"+dir;
                String outputFileName = outputDirectory+"//"+reportId + "-" +versionNumber+"." +documentType.toLowerCase();
                    outDirectory = new File(outputDirectory);
                    if(outDirectory.mkdirs())
                    {
                        //System.out.println("New Directory is created");
                        log.info("New Version Directory is created");
                    }
                    //System.out.println("outputDirectory" +outputDirectory);
                    log.info("OutputDirectory" + outputDirectory);
                contentOutputFileName=new File(outputFileName);
                contentStream =  new FileOutputStream (contentOutputFileName);
                contentStream.write(bytes);
                contentStream.flush();

            }
            //catch (Exception iex) 
            //{
            //  log.error("IOExceptionException ", iex);
                //iex.printStackTrace();
            //}
            finally
            {
                //if(contentStream!=null){


                outputStream.close();
                contentStream.close();


                    //} 

0 个答案:

没有答案