how to read a file from server in play framework

前端 未结 4 2068
悲哀的现实
悲哀的现实 2021-02-07 13:16

I have the following file

/app/menus/menu1.yml

and I\'d like to read it\'s contents

--

short answer:

fileConten         


        
4条回答
  •  执念已碎
    2021-02-07 13:52

    Play includes the SnakeYAML parser. From their docs:

    Yaml yaml = new Yaml();
    String document = "\n- Hesperiidae\n- Papilionidae\n- Apatelodidae\n- Epiplemidae";
    List list = (List) yaml.load(document);
    System.out.println(list);
    

    ['Hesperiidae', 'Papilionidae', 'Apatelodidae', 'Epiplemidae']

    There is also a version of Yaml.load that takes an InputStream, which is demonstrated in this sample code: http://code.google.com/p/snakeyaml/source/browse/src/test/java/examples/LoadExampleTest.java

提交回复
热议问题