SpringBoot Resource Load

By | 2020년 7월 21일
public static String readResource(String resourceName) {
  ClassPathResource resource = new ClassPathResource(resourceName);
  try {
    StringBuilder textBuilder = new StringBuilder();
    try (Reader reader = new BufferedReader(new InputStreamReader
        (resource.getInputStream(), Charset.forName(StandardCharsets.UTF_8.name())))) {
      int c = 0;
      while ((c = reader.read()) != -1) {
        textBuilder.append((char) c);
      }
    }
    return textBuilder.toString();
  } catch (IOException e) {
    log.error("", e);
  }
  return null;
}

resources 아래 경로 부터 써주면 됨.