How to create a file in src/main/resources

前端 未结 4 1191
盖世英雄少女心
盖世英雄少女心 2021-01-23 12:42

If I do this

fis = new FileInputStream(new File(\".\").getAbsolutePath() + \"/sudoinput.txt\");

Its trying to write to this location on the ser

4条回答
  •  自闭症患者
    2021-01-23 13:24

    Agree with Sandiip Patil. If you didn't have folder inside your resources then path will be /sudoinput.txt or in folder /folder_name/sudoinput.txt. For getting file from resources you should use YourClass.class.getResource("/filename.txt");

    For example

    Scanner scanner = new Scanner(TestStats.class.getResourceAsStream("/123.txt"));
    

    or

    Scanner scanner = new Scanner(new `FileInputStream(TestStats.class.getResource("/123.txt").getPath()));`
    

    Also look at: this

提交回复
热议问题