- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to convert File into a Stream in Java?
Let’s say we have a file “input.txt” here in the directory E:/ with the following content:
Open a file with Bufferedreader. We have taken the above file here which is located at E: directory;
BufferedReader buffReader = Files.newBufferedReader(Paths.get("E:\input.txt"),StandardCharsets.UTF_8);
Now get the stream of lines from the above file and display:
buffReader.lines().forEach(System.out::println);
The following is an example to convert File into a Stream in Java:
Example
import java.io.BufferedReader; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; public class Demo { public static void main(String[] argv) throws Exception { BufferedReader buffReader = Files.newBufferedReader(Paths.get("E:\input.txt"), StandardCharsets.UTF_8); System.out.println("Stream of lines..."); buffReader.lines().forEach(System.out::println); } }
Output
Stream of lines... Amit Tom David Andre Keemo Gayle
- Related Articles
- How to convert/read an input stream into a string in java?
- How to convert Stream to TreeSet in Java?
- Convert Stream to Set in Java
- How to Convert a Java 8 Stream to an Array?
- Program to convert a Map to a Stream in Java
- How to convert string Stream to join them in Java?
- Convert an Iterator to Stream in Java
- Convert an Iterable to Stream in Java
- Convert All Lowercase Text of a File into Uppercase in Java?
- How to convert XML file into array in PHP?
- Program to convert List to Stream in Java
- Java Program to convert Stream to List
- How to convert a Kotlin source file to a Java source file?
- How to convert an input stream to byte array in java?
- Program to convert a Set to Stream in Java using Generics

Advertisements