繁体   English   中英

读取 java 中文件的特定部分

[英]Read specific parts of File in java

我需要读取具有以下结构的文件

在文件中,我首先要分离deps内容和outs内容。

分离之后,我需要分离以-md5开头的块,直到找到另一个块。

例如,在图片中, deps部分有 2 个块,而outs部分有 3 个块。

目前我正在使用LineNumberReader首先分离depsouts ,然后创建deps内容和outs内容的ArrayList ,但我认为这不是很好,因为我需要分离下一个由-md5启动的块以防万一我有不止一个。

这就是我假装的

我怎样才能以更好的方式做到这一点? 谢谢你的帮助。

The syntax of the file type you are trying to read is YAML , so if you need to parse the file and map it to an already defined class, you can use Jackson .

那么映射过程就很简单了:

ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
try {
        YourCustomClass obj = mapper.readValue(new File("YourFilePath.yaml"), YourCustomClass.class);
        System.out.println(obj.getProperty());
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

顺便说一句,如果您正在使用 maven,您可以安装 Jackson。


暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM