Read only part of a .txt file in Java

-1
Hello, I'm developing a Discord bot and wanted it to take the Guild ID and Chat I made it write automatically when someone typed -setarbot Guild: 430119147146444807 Channel: 437245715576520716 in a file called guilds.yml and I wanted to do something to read this file just get the Guild ID and Channel

and then do return true with a boolean.

    
asked by anonymous 16.07.2018 / 18:28

1 answer

0

Dependencies on the pom.xml file

<dependency>
    <groupId>com.fasterxml.jackson.dataformat</groupId>
    <artifactId>jackson-dataformat-yaml</artifactId>
    <version>2.3.0</version>
</dependency>

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.2.3</version>
</dependency>

<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-lang3</artifactId>
    <version>3.4</version>
</dependency>

Do not forget to pass the Path of the Archic correctly

  ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    try {
        Map<String, String> map = mapper.readValue(new File("guilds.yaml"), Map.class);
        System.out.println(ReflectionToStringBuilder.toString(mapToStringStyle.MULTI_LINE_STYLE));
        System.out.println(map.get("id"))
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();

    }
    
16.07.2018 / 18:47