简体   繁体   中英

What should be path for the files that are in resources folder in spring boot

I want to access the certificate file what should be the path if that file is in resources/certs/ folder.

I tried it with the classpath put still getting the exception FileNotFound .

what should be path for that I should specify for this in my application.properties .

在此处输入图片说明

if you want to read a file, you can use this code (fileName: "/certs/xxx")

public String readFile(String fileName) throws IOException {
        InputStream inputStream = this.getClass().getResourceAsStream(fileName);
        StringBuilder resultStringBuilder = new StringBuilder();
        try (BufferedReader br = new BufferedReader(new InputStreamReader(inputStream))) {
            String line;
            while ((line = br.readLine()) != null) {
                resultStringBuilder.append(line).append("\n");
            }
        }
        return resultStringBuilder.toString();
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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