FileNotFoundException尽管find返回绝对路径

时间:2019-03-11 13:33:14

标签: java

我正在尝试使用draftable的API来比较两个PDF,如果我使用其文档中的两个文档,它会很好地工作。当我定义两个本地文件时,我得到一个java.io.FileNotFoundException: version1.pdf (No such file or directory)

可撰写的API:https://api.draftable.com/api-explorer#!/Comparison/createComparison

在API中,可以上传两个本地文件,并且工作正常。他们是否将其上传并存储在其末端,并使用面向公众的URL再次在其API上使用它?

我当前的代码:

logger.info("Main started");

        String accountId = "*****"; // From https://api.draftable.com/account/credentials under "Account ID"
        String authToken = "*****"; // From the same page, under "Auth Token"

        /**
         * Demo with Local Files
         **/
        File leftFile = new File("version1.pdf");
        File rightFile = new File("version2.pdf");
        logger.info("Left File: " + leftFile.getAbsolutePath());
        logger.info("Right File: " + rightFile.getAbsolutePath());
        Side left = Side.create(leftFile, "pdf");
        Side right = Side.create(rightFile, "pdf");
        logger.info("Left Document: " + left);
        logger.info("Right Document: " + right);

        Comparisons comparisons = new Comparisons(accountId, authToken);

        try {
            logger.info("---CREATING COMPARISON---");
            Comparison comparison = comparisons.createComparison(left, right);
            String viewerURL = comparisons.signedViewerURL(comparison.getIdentifier(), Duration.ofMinutes(30), false);

            System.out.println("Comparison created: " + comparison);
            System.out.println("Viewer URL (expires in 30 min): " + viewerURL);
            logger.info("---COMPARISON COMPLETED---");
        } catch (IOException e) {
            logger.error(e);
        }

这是我得到的控制台日志:

14:18:31.722 [main] INFO  example.NewComparison - Main started
14:18:31.724 [main] INFO  example.NewComparison - Left File: /Users/In0cenT/Documents/Dev/Test_pdfDiff/version1.pdf
14:18:31.724 [main] INFO  example.NewComparison - Right File: /Users/In0cenT/Documents/Dev/Test_pdfDiff/version2.pdf
14:18:31.732 [main] INFO  example.NewComparison - Left Document: com.draftable.api.client.Comparisons$Side@44a59da3
14:18:31.732 [main] INFO  example.NewComparison - Right Document: com.draftable.api.client.Comparisons$Side@27e47833
14:18:31.733 [main] INFO  example.NewComparison - ---CREATING COMPARISON---
14:18:31.740 [main] ERROR example.NewComparison - java.io.FileNotFoundException: version1.pdf (No such file or directory)

我想念什么?

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

我将首先使用leftFile.exists()rightFile.exists()检查文件。 我认为问题在于您的路径中没有这些文件。