Answers for "load a file from classpath spring boot"

1

load a file from classpath spring boot

public void testResourceFile() throws IOException {
		File resource = new ClassPathResource("test.json").getFile();
		String text = new String(Files.readAllBytes(resource.toPath()));
	}
Posted by: Guest on June-19-2020
1

load a file from classpath spring boot

    private void testResource(Resource resource) {
		try {
			InputStream resourcee = resource.getInputStream();
			String text = null;
			try (final Reader reader = new InputStreamReader(resourcee)) {
				text = CharStreams.toString(reader);
			}
			System.out.println(text);
 
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
Posted by: Guest on June-19-2020

Code answers related to "load a file from classpath spring boot"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language