💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
# 组件源码 ``` /** * <b>方法描述:</b> 读文件内容 <br/> * <b>创建者:</b> admin <br/> * <b>创建时间:</b> 2018-05-08 17:19:05 <br/> * * @param filename * 入参|文件名|{@link java.lang.String} * @param charset * 入参|字符集GBK或UTF-8|{@link java.lang.String} * @param contents * 出参|读取内容|{@link java.lang.String} * @return -1 异常<br/> * 0 失败<br/> * 1 成功<br/> */ @Component(label = "读文件内容", style = "判断型", type = "同步组件", version = "1.0.0", deprecated = false, author = "admin", date = "2018-05-08 05:19:05") @InParams(param = { @Param(name = "filename", comment = "文件名", type = java.lang.String.class), @Param(name = "charset", comment = "字符集GBK或UTF-8", type = java.lang.String.class) }) @OutParams(param = { @Param(name = "contents", comment = "读取内容", type = java.lang.String.class) }) @Returns(returns = { @Return(id = "-1", desp = "异常"), @Return(id = "0", desp = "失败"), @Return(id = "1", desp = "成功") }) public static ResultBase P_fileReadAll(String filename, String charset) { if (filename == null || filename == "") { return ResultBase.newFailureResult("TPTF0028", "文件名不能为空"); } File file = new File(filename); Long filelength = file.length(); byte[] filecontent = new byte[filelength.intValue()]; try { FileInputStream in = new FileInputStream(file); in.read(filecontent); in.close(); } catch (Exception e) { AppLog.error(e); return ResultBase.newExceptionResult("TPTF0029", "读取文件失败," +AppLog.errorMsg(e)); } try { return ResultBase .newSuccessResult(new String(filecontent, charset)); } catch (UnsupportedEncodingException e) { AppLog.error(e); return ResultBase.newExceptionResult("TPTF0030", "字符集转换失败," + AppLog.errorMsg(e)); } } ``` # 交易中组件使用方式 ![](https://img.kancloud.cn/1f/8a/1f8a26c9e609e73ba5e4ae054f3fe0cc_1870x895.png) # 参数说明及示例 ## 入口参数 文件名:文件的绝对路径,示例: `"D:\\work\\CQYY\\workspace\\xxx.txt"` 字符集GBK或UTF-8:文件字符集编码,示例: `"utf-8"` ## 出口参数 读取内容:读取文件的内容,示例: `__INNER__["result"]`