企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# 组件源码 ``` /** * <b>方法描述:</b> 读文件行 <br/> * <b>创建者:</b> admin <br/> * <b>创建时间:</b> 2018-05-08 17:17:18 <br/> * * @param filename * 入参|文件名|{@link java.lang.String} * @param charset * 入参|字符集GBK或UTF-8|{@link java.lang.String} * @param lineno * 入参|行号|{@link int} * @param lineinfo * 出参|读取内容|{@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:17:18") @InParams(param = { @Param(name = "filename", comment = "文件名", type = java.lang.String.class), @Param(name = "charset", comment = "字符集GBK或UTF-8", type = java.lang.String.class), @Param(name = "lineno", comment = "行号", type = int.class) }) @OutParams(param = { @Param(name = "lineinfo", comment = "读取内容", type = java.lang.String.class) }) @Returns(returns = { @Return(id = "-1", desp = "异常"), @Return(id = "0", desp = "失败"), @Return(id = "1", desp = "成功") }) public static ResultBase P_fileReadLine(String filename, String charset, int lineno) { if (filename == null || filename == "") { return ResultBase.newFailureResult("TPTF0022", "文件名不能为空"); } FileInputStream fs = null; String strRet = ""; try { fs = new FileInputStream(filename); InputStreamReader inReader = new InputStreamReader(fs, charset); BufferedReader bufReader = new BufferedReader(inReader); for (int i = 0; i < lineno; i++) { strRet = bufReader.readLine(); if (strRet == null) { fs.close(); return ResultBase.newFailureResult("TPTF0023", "取行数:"+lineno+" 超过文件行数:"+i); } } fs.close(); } catch (Exception ex) { AppLog.error(ex); if (fs != null) { try { fs.close(); } catch (Exception e) { AppLog.error(e); } } return ResultBase.newExceptionResult("TPTF0024", "读取文件行异常"+AppLog.errorMsg(ex)); } return ResultBase.newSuccessResult(strRet); } ``` # 交易中组件使用方式 ![](https://img.kancloud.cn/43/8c/438cb7ca29a6dac07f9a69068dd6d536_1867x892.png) # 参数说明及示例 ## 入口参数 文件名:输入需要读取的文件绝对路径,示例: `"D:\\work\\CQYY\\workspace\\xxx.txt"` 字符集GBK或UTF-8:设置文件字符集,示例: `"utf-8"` 行号:需要读取文件中的第几行,示例: `3` ## 出口参数 读取内容:读取文件的内容,示例: `__INNER__["result"]`