viper25

Read Text from a file as a Stream

Sep 16th, 2016
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.47 KB | None | 0 0
  1. //Read a text file as a Stream
  2.  
  3. try (InputStream inputStream =
  4. Thread.currentThread().getContextClassLoader().getResourceAsStream(PUT_RECORD_STREAM_SOURCE)) {
  5. if (inputStream == null)
  6. {
  7.     throw new FileNotFoundException("Could not find file " + PUT_RECORD_STREAM_SOURCE);
  8. }
  9.  
  10. try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)))
  11. {
  12.     String line = null;
  13.     while ((line = reader.readLine()) != null)
  14.     {
  15.         String data = line + "\n";
  16.     }
  17. }
Add Comment
Please, Sign In to add comment