java.nio.fileFile, Files, Path, Paths

this.getClass().getClassLoader().getResource()?

this.getClass()
        .getClassLoader()
        .getResource(fileName);
@Test
void 파일의_내용을_읽는다() throws URISyntaxException, IOException {
    final String fileName = "nextstep.txt";

    final URL fileUrl = this.getClass()
            .getClassLoader()
            .getResource(fileName);
    final Path path = Paths.get(fileUrl.toURI());
    
    final List<String> actual = Files.readAllLines(path);

    assertThat(actual).containsOnly("nextstep");
}

IOStream

InputStream

@Test
void InputStream은_데이터를_바이트로_읽는다() throws IOException {
    byte[] bytes = {-16, -97, -92, -87};
    final InputStream inputStream = new ByteArrayInputStream(bytes);

    /**
     * todo
     * inputStream에서 바이트로 반환한 값을 문자열로 어떻게 바꿀까?
     */
    final StringBuilder textBuilder = new StringBuilder();
    try (Reader reader = new BufferedReader(new InputStreamReader
            (inputStream, Charset.forName(StandardCharsets.UTF_8.name())))) {
        int c = 0;
        while ((c = reader.read()) != -1) {
            textBuilder.append((char) c);
        }
    }
    final String actual = textBuilder.toString();

    assertThat(actual).isEqualTo("🤩");
    assertThat(inputStream.read()).isEqualTo(-1);
    inputStream.close();
}

@Test
void InputStream은_데이터를_바이트로_읽는다() throws IOException {
    byte[] bytes = {-16, -97, -92, -87};
    final InputStream inputStream = new ByteArrayInputStream(bytes);
    
		/**
     * todo
     * inputStream에서 바이트로 반환한 값을 문자열로 어떻게 바꿀까?
     */
    final String actual = new String(inputStream.readAllBytes());

    assertThat(actual).isEqualTo("🤩");
    assertThat(inputStream.read()).isEqualTo(-1);
    inputStream.close();
}