Created
January 20, 2022 08:17
-
-
Save nhomble/384ce2cade25abb93c538f4b6ac20ed0 to your computer and use it in GitHub Desktop.
first example of java streams to read a file into string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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