{"record":{"id":"7ef69c322254e3cd","repo":"flowable/flowable-engine","slug":"couldn-t-read-file-filepath-e-getmessage-7ef69c","errorCode":null,"errorMessage":"Couldn't read file ${filePath}: ${e.getMessage()}","messagePattern":"Couldn't read 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":57,"sourceCode":"            int bytesRead = inputStream.read(buffer);\n            while (bytesRead != -1) {\n                outputStream.write(buffer, 0, bytesRead);\n                bytesRead = inputStream.read(buffer);\n            }\n        } catch (Exception e) {\n            throw new ActivitiException(\"couldn't read input stream \" + inputStreamName, e);\n        }\n        return outputStream.toByteArray();\n    }\n\n    public static String readFileAsString(String filePath) {\n        byte[] buffer = new byte[(int) getFile(filePath).length()];\n        BufferedInputStream inputStream = null;\n        try {\n            inputStream = new BufferedInputStream(new FileInputStream(getFile(filePath)));\n            inputStream.read(buffer);\n        } catch (Exception e) {\n            throw new ActivitiException(\"Couldn't read file \" + filePath + \": \" + e.getMessage());\n        } finally {\n            IoUtil.closeSilently(inputStream);\n        }\n        return new String(buffer);\n    }\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 {","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/util/IoUtil.java#L39-L75","documentation":"IoUtil.readFileAsString loads a classpath-relative file into a String via a BufferedInputStream. Any failure opening or reading the file (missing file, permission, IO error) is rethrown as ActivitiException including the file path and the cause's message.","triggerScenarios":"Calling IoUtil.readFileAsString(filePath) where the resource resolves on the classpath but FileInputStream fails — file absent at that location, is a directory, or is unreadable.","commonSituations":"Resources not packaged in the artifact (missing from src/main/resources); case-sensitive classpath mismatches on Linux; reading files inside nested jars which File-based access cannot handle.","solutions":["Verify the file exists at the exact classpath-relative path (check spelling and case).","Include the resource in the build (src/main/resources).","For resources inside jars, read via ClassLoader.getResourceAsStream instead of File.","Check file permissions on the target resource."],"exampleFix":"// before\nString content = IoUtil.readFileAsString(\"config/app.properties\"); // not packaged\n// after (move file to src/main/resources/config/app.properties) or read via stream:\ntry (InputStream in = IoUtil.class.getClassLoader().getResourceAsStream(\"config/app.properties\")) {\n    String content = new String(in.readAllBytes(), StandardCharsets.UTF_8);\n}","handlingStrategy":"validation","validationCode":"URL url = IoUtil.class.getClassLoader().getResource(filePath);\nif (url == null) throw new IllegalStateException(\"Resource not on classpath: \" + filePath);\nif (!\"file\".equals(url.getProtocol())) throw new IllegalStateException(\"Resource is not file-accessible: \" + url);","typeGuard":null,"tryCatchPattern":"try {\n    String s = IoUtil.readFileAsString(path);\n} catch (ActivitiException e) {\n    if (e.getMessage().startsWith(\"Couldn't read file\")) { /* fall back to classpath stream */ }\n}","preventionTips":["Verify resources are packaged in src/main/resources and included in the artifact","Match case exactly — classpath lookups are case-sensitive on Linux","Prefer getResourceAsStream over File-based access for portable resource loading"],"tags":["io","classpath","file"],"backgroundTag":"file-read-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"}