java读取并解析linux上E文件

发布时间:2024-12-19 16:04

在Linux系统中,使用Docker容器化文件结构 #生活技巧# #组织技巧# #文件管理系统#

最新推荐文章于 2023-10-10 11:07:07 发布

杨小猪 于 2019-09-02 11:22:26 发布

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。

E文件格式: <! System=OMS Version=1.0 Code=GB2312 Data=1.0 !> <XLJH> @ 序号 名称 ... # 1 杨小猪 ... </XLJH> /** * 读文件 * eFileName : 读取文件的文件名 * node : E文件里的节点名称 */ public static List<List<String>> readEFile(String eFileName, String node){ String path = "/path..." + "/"+ eFileName; try { int startIndex = 0; int thisIndex = 0; int endIndex = 0; boolean flag = false; //文件内容的字符集 UTF8 BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(path),"UTF8")); String line = reader.readLine(); List<List<String>> listDatas = new ArrayList<List<String>>(); while ((line = reader.readLine()) != null && flag == false) { thisIndex++; if(line.startsWith("<"+node)){ startIndex = thisIndex; } else if(line.startsWith("</"+node)){ endIndex = thisIndex; flag = true; } else if(startIndex != 0){ String[] split = line.split("\\s+"); List<String> lineDatas = new ArrayList<String>(Arrays.asList(split)); lineDatas.remove(0);// listDatas.add(lineDatas); } } System.err.println(node+"节点标签在第"+startIndex+"-"+endIndex); reader.close(); return listDatas; } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }

/** * 写文件 */ public static void writeTxt(String txtInfo,String fileName) throws IOException { String filePath = "/path" + "/"+fileName; File file = new File(filePath); if (!file.exists()) { file.getParentFile().mkdirs(); } file.createNewFile(); // write 解决中文乱码问题 // FileWriter fw = new FileWriter(file, true); // 写入文件的字符集 GBK 看需求而设定 OutputStreamWriter fw = new OutputStreamWriter(new FileOutputStream(file), "GBK"); BufferedWriter bw = new BufferedWriter(fw); bw.write(txtInfo); bw.flush(); bw.close(); fw.close(); }

网址:java读取并解析linux上E文件 https://www.yuejiaxmz.com/news/view/519204

相关内容

Linux频繁存取文件,导致可用内存逐渐减少
Linux环境下安装并配置Java JDK环境配置
39、File文件的基本操作
Linux技巧
【Java报错已解决】Driver class ‘net.sourceforge.jtds.jdbc.Driver’ could not be found, make sure the
java软件工程师
Linux系统内存清理神器:Purge命令详解 – Linux命令大全(手册)
7 个整理 Linux 文件和清理电脑的技巧
Linux操作系统安全分析与防护
如何在Linux上自动化任务

随便看看