SpringBoot 如何读取resource 下的文件

show the code

        String filename = "onboardScript.js";
        try {
            ClassPathResource resource = new ClassPathResource(filename);
            InputStream inputStream = resource.getInputStream();
            String fileContent = new String(FileCopyUtils.copyToByteArray(inputStream), StandardCharsets.UTF_8);
            System.out.println(fileContent);
        } catch (IOException e) {
            System.out.println("File not found: " + filename);
        }
    }

你可能感兴趣的:(spring,boot,java,spring)