Skip to content

Instantly share code, notes, and snippets.

@nhomble
Created January 20, 2022 08:17
Show Gist options
  • Save nhomble/384ce2cade25abb93c538f4b6ac20ed0 to your computer and use it in GitHub Desktop.
Save nhomble/384ce2cade25abb93c538f4b6ac20ed0 to your computer and use it in GitHub Desktop.
first example of java streams to read a file into string
import java.io.*;
public class ExampleFileIO {
public static void main(String[] args) {
try (InputStream is = ExampleFileIO.class.getClassLoader().getResourceAsStream("list.txt");
InputStreamReader reader = new InputStreamReader(is);
BufferedReader bufferedReader = new BufferedReader(reader);
) {
String s;
while ((s = bufferedReader.readLine()) != null) {
System.out.println(s);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment