{"record":{"id":"08a41003ddc827f5","repo":"flowable/flowable-engine","slug":"couldn-t-write-file-filepath","errorCode":null,"errorMessage":"Couldn't write file ${filePath}","messagePattern":"Couldn't write file (.+?)","errorType":"exception","errorClass":"FlowableException","httpStatus":null,"severity":"error","filePath":"modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/util/IoUtil.java","lineNumber":80,"sourceCode":"    }\n\n    public static File getFile(String filePath) {\n        URL url = IoUtil.class.getClassLoader().getResource(filePath);\n        try {\n            return new File(url.toURI());\n        } catch (Exception e) {\n            throw new FlowableException(\"Couldn't get file \" + filePath + \": \" + e.getMessage());\n        }\n    }\n\n    public static void writeStringToFile(String content, String filePath) {\n        BufferedOutputStream outputStream = null;\n        try {\n            outputStream = new BufferedOutputStream(new FileOutputStream(getFile(filePath)));\n            outputStream.write(content.getBytes());\n            outputStream.flush();\n        } catch (Exception e) {\n            throw new FlowableException(\"Couldn't write file \" + filePath, e);\n        } finally {\n            IoUtil.closeSilently(outputStream);\n        }\n    }\n\n    /**\n     * Closes the given stream. The same as calling {@link InputStream#close()}, but errors while closing are silently ignored.\n     */\n    public static void closeSilently(InputStream inputStream) {\n        try {\n            if (inputStream != null) {\n                inputStream.close();\n            }\n        } catch (IOException ignore) {\n            // Exception is silently ignored\n        }\n    }\n","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/util/IoUtil.java#L62-L98","documentation":"Flowable wraps any exception thrown while writing a string to a file at the given path into a FlowableException with this message. It is thrown by IoUtil.writeStringToFile when opening, writing to, or flushing the FileOutputStream fails, and the original exception is preserved as the cause.","triggerScenarios":"Calling IoUtil.writeStringToFile(filePath, content) when the target directory does not exist, the path is a directory, the file cannot be opened (permissions, invalid path), or an I/O error occurs mid-write/flush.","commonSituations":"Generating process diagram/report files into a directory that was never created; read-only filesystems or containers; invalid paths from configuration (e.g. wrong resource folder); disk full.","solutions":["Read the 'cause' field of the FlowableException to see the underlying IOException (NoSuchFileException, AccessDeniedException, etc.).","Create all parent directories before writing (Files.createDirectories on the parent path).","Verify the filePath is a valid file path, not a directory, and is writable by the process user.","Check disk space and filesystem permissions.","If only the output location is wrong, fix the configured output directory."],"exampleFix":"// before\nIoUtil.writeStringToFile(\"target/reports/diagram.svg\", svg);\n// after\nFiles.createDirectories(Paths.get(\"target/reports\"));\nIoUtil.writeStringToFile(\"target/reports/diagram.svg\", svg);","handlingStrategy":"validation","validationCode":"Path path = Paths.get(filePath);\nif (!Files.exists(path.getParent())) Files.createDirectories(path.getParent());\nif (Files.isDirectory(path)) throw new IllegalStateException(\"Path is a directory: \" + filePath);\nif (!Files.isWritable(path.getParent())) throw new IllegalStateException(\"Not writable: \" + path.getParent());","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always create parent directories before writing generated files","Validate configured output paths at startup, not at write time","Ensure the runtime user has write permission on the output directory","Monitor disk space in containerized deployments"],"tags":["io","file-write","java"],"backgroundTag":"file-write-failed","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-18T11:17:12.947Z"}