讀取resources目錄下文件方式

        //spring方式
        Resource resource = new ClassPathResource("application.properties");
        String path = ((ClassPathResource) resource).getURL().getPath();
        System.out.println(path);

        //jdk方式
        String path2 = (new App()).getClass().getResource("/").getPath();
        FileInputStream inputStream = new FileInputStream(path2 + "application.properties");
        Properties properties = new Properties();
        properties.load(inputStream);
        System.out.println(path2);

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章