{"record":{"id":"0fcf4841a1ae7bf8","repo":"flowable/flowable-engine","slug":"couldn-t-write-file-filepath-0fcf48","errorCode":null,"errorMessage":"Couldn't write file ${filePath}","messagePattern":"Couldn't write file (.+?)","errorType":"exception","errorClass":"org.activiti.engine.ActivitiException","httpStatus":null,"severity":"error","filePath":"modules/flowable5-engine/src/main/java/org/activiti/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 ActivitiException(\"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 ActivitiException(\"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/flowable5-engine/src/main/java/org/activiti/engine/impl/util/IoUtil.java#L62-L98","documentation":"IoUtil.writeStringToFile writes a string to a classpath-resolved file via BufferedOutputStream. Any exception — including failure resolving the file (see getFile) or an I/O write/flush error — is wrapped in ActivitiException 'Couldn't write file <filePath>' with the original cause chained.","triggerScenarios":"Calling IoUtil.writeStringToFile(content, filePath) where getFile(filePath) fails (resource not on classpath) or FileOutputStream/write/flush throws (read-only directory, permissions, disk full).","commonSituations":"Trying to write into a jar or immutable classpath location; read-only deployment directory; missing write permissions for the process user.","solutions":["Check the chained cause (e.getCause()) to distinguish resolution vs. write failure.","Ensure the target location is a writable directory on the filesystem, not inside a jar.","Grant write permissions to the process user for the target directory.","Use plain java.nio (Files.writeString) with a real filesystem path for non-classpath targets."],"exampleFix":"// before\nIoUtil.writeStringToFile(content, \"output/result.txt\"); // read-only dir\n// after\nPath target = Paths.get(System.getProperty(\"java.io.tmpdir\"), \"result.txt\");\nFiles.writeString(target, content);","handlingStrategy":"try-catch","validationCode":"Path dir = Paths.get(outputDir);\nif (!Files.isWritable(dir)) throw new IllegalStateException(\"Not writable: \" + dir);","typeGuard":null,"tryCatchPattern":"try {\n    IoUtil.writeStringToFile(content, path);\n} catch (ActivitiException e) {\n    if (e.getMessage().startsWith(\"Couldn't write file\")) {\n        Throwable c = e.getCause();\n        if (c != null && String.valueOf(c.getMessage()).contains(\"Permission\")) { /* fix permissions */ }\n    }\n}","preventionTips":["Never write into classpath/jar locations; resolve a real writable filesystem path first","Pre-create the target directory and verify write permissions for the runtime user","Prefer java.nio.file.Files.write for application output instead of classpath-relative helpers"],"tags":["io","file-write","permissions"],"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"}