๐ŸŒ
Programiz
programiz.com โ€บ java-programming โ€บ reader
Java Reader (With Example)
Let's try to read this file using ... array of character char[] array = new char[100]; try { // Creates a reader using the FileReader Reader input = new FileReader("input.txt"); // Checks if reader is ready System.out.println("Is there data in the stream?...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ java-io-reader-class-java
Java Reader Class - GeeksforGeeks
December 10, 2025 - It implements the Readable interface that defines the read(CharBuffer cb) method. It implements the Closeable interface that defines the close() method to release resources. ... Example: Read a text file character by character using the Reader class.
Discussions

Java, reading from files?
Lee J is having issues with: So i found this simple method to read from a text document: More on teamtreehouse.com
๐ŸŒ teamtreehouse.com
1
April 10, 2018
There are so many Reader classes. Which one should I use to read from a file?
There are 2 axes to think about: What am I reading? Binary or text? If I'm reading binary, use an InputStream. If I'm reading text, use a Reader. A Reader basically wraps an InputStream and handles the conversion from whatever encoding was used to store the text (e.g., UTF-8, ISO-8859-1, etc.) What do I have? If you have a File, use a FileInputStream or FileReader. If you already have an InputStream, use an InputStreamReader. The other thing is that these things "stack". So if you have a File with some text, probably the best thing to do is to create a new BufferedReader(new FileReader(file)) BufferedReader is nice because you can read one line at a time using readLine(). BUT, there's a glitch here, which is that doing it that way doesn't set you specify how text in the file was actually encoded. So what you really need to do is: new BufferedReader(new InputStreamReader(new FileInputStream(file), "utf-8")) Hope that helps. More on reddit.com
๐ŸŒ r/java
14
30
September 2, 2012
Decorator pattern java.io.reader - Stack Overflow
For a school report I have to explain how the java.io.Reader package implements the Decorator pattern. I have seen multiple explanations for the java.io package (here for example) but not for the j... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Java - Reading from a Socket using a BufferedReader object
Hello, I need help understanding how the readline() method of a BufferedReader object works in Java. From what I understanding when a BufferedReader object reads from a file using the readline() method it reads the file line by line and when there is nothing left to read the method returns a... More on forum.allaboutcircuits.com
๐ŸŒ forum.allaboutcircuits.com
4
December 3, 2014
๐ŸŒ
Oracle
docs.oracle.com โ€บ javase โ€บ 7 โ€บ docs โ€บ api โ€บ java โ€บ io โ€บ Reader.html
Reader (Java Platform SE 7 )
Resets the stream. If the stream has been marked, then attempt to reposition it at the mark. If the stream has not been marked, then attempt to reset it in some way appropriate to the particular stream, for example by repositioning it to its starting point.
๐ŸŒ
W3Schools
w3schools.com โ€บ java โ€บ java_files_read.asp
Java Read Files
Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, Python, PHP, Bootstrap, Java, XML and more.
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ java โ€บ java io โ€บ guide to bufferedreader
Guide to BufferedReader | Baeldung
January 8, 2024 - Simply put, it enables us to minimize the number of I/O operations by reading chunks of characters and storing them in an internal buffer. While the buffer has data, the reader will read from it instead of directly from the underlying stream. Like most of the Java I/O classes, BufferedReader implements Decorator pattern, meaning it expects a Reader in its constructor.
๐ŸŒ
Jenkov
jenkov.com โ€บ tutorials โ€บ java-io โ€บ reader.html
Java Reader
August 27, 2019 - This example tells the Java Reader to skip over the next 24 characters in the Reader. The skip() method returns the actual number of characters skipped.
๐ŸŒ
CodeGym
codegym.cc โ€บ java blog โ€บ java io & nio โ€บ java filereader class
Java FileReader Class
February 20, 2025 - // 1) Using a string path import java.io.FileReader; import java.io.IOException; public class FileReaderStringPathExample { public static void main(String[] args) { try (FileReader reader = new FileReader("example.txt")) { int data; while ((data ...
Find elsewhere
๐ŸŒ
Oracle
docs.oracle.com โ€บ javase โ€บ 8 โ€บ docs โ€บ api โ€บ java โ€บ io โ€บ Reader.html
Reader (Java Platform SE 8 )
April 21, 2026 - Resets the stream. If the stream has been marked, then attempt to reposition it at the mark. If the stream has not been marked, then attempt to reset it in some way appropriate to the particular stream, for example by repositioning it to its starting point.
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ java โ€บ java io โ€บ a guide to the java filereader class
A Guide to the Java FileReader Class | Baeldung
February 8, 2025 - Thereโ€™s a subtle difference in the return value of read() when it comes to reading multiple characters in an array. The return value here is either the number of characters read or -1 if the reader has reached the end of the input stream.
๐ŸŒ
Coding Shuttle
codingshuttle.com โ€บ home โ€บ handbooks โ€บ java programming handbook โ€บ java reader and writer class
Java Reader and Writer Class | Coding Shuttle
April 9, 2025 - Reader: Abstract class for reading character streams. Writer: Abstract class for writing character streams. They are used when working with text data, unlike InputStream and OutputStream which work with binary data.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ reader-read-method-in-java-with-examples
Reader read() method in Java with Examples - GeeksforGeeks
July 11, 2025 - // Java program to demonstrate // Reader read() method import java.io.*; import java.util.*; class GFG { public static void main(String[] args) { try { String str = "GeeksForGeeks"; // Create a Reader instance Reader reader = new StringReader(str); ...
๐ŸŒ
Team Treehouse
teamtreehouse.com โ€บ community โ€บ java-reading-from-files
Java, reading from files? (Example) | Treehouse Community
April 10, 2018 - import java.io.*; public class Main { public static void main(String[] args) throws Exception { File file = new File("C:\\Users\\A\\Desktop\\test.txt"); BufferedReader br = new BufferedReader(new FileReader(file)); String test = br.readLine() }
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ java-read-file-line-by-line
Java Read File: Complete Guide with Examples | DigitalOcean
February 20, 2025 - Here is an example program to read a file line-by-line with BufferedReader: ... package com.journaldev.readfileslinebyline; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; public class ReadFileLineByLineUsingBufferedReader { public static void main(String[] args) { BufferedReader reader; try { reader = new BufferedReader(new FileReader("sample.txt")); String line = reader.readLine(); while (line != null) { System.out.println(line); // read next line line = reader.readLine(); } reader.close(); } catch (IOException e) { e.printStackTrace(); } } }
๐ŸŒ
o7planning
o7planning.org โ€บ 13417 โ€บ java-reader
Java Reader Tutorial with Examples | o7planning.org
package org.o7planning.reader.ex; ... main(String[] args) throws IOException { // StringReader is a subclass of Reader. Reader reader = new StringReader("123456789-987654321-12345"); // Create a temporary char array....
๐ŸŒ
Reddit
reddit.com โ€บ r/java โ€บ there are so many reader classes. which one should i use to read from a file?
r/java on Reddit: There are so many Reader classes. Which one should I use to read from a file?
September 2, 2012 -

Java has so many options to read from a file. One can use a BufferedReader, FileReader, InputStreamReader, FileInputStream etc. I've never understood which one to use and when. Can someone please explain?

Top answer
1 of 5
11
There are 2 axes to think about: What am I reading? Binary or text? If I'm reading binary, use an InputStream. If I'm reading text, use a Reader. A Reader basically wraps an InputStream and handles the conversion from whatever encoding was used to store the text (e.g., UTF-8, ISO-8859-1, etc.) What do I have? If you have a File, use a FileInputStream or FileReader. If you already have an InputStream, use an InputStreamReader. The other thing is that these things "stack". So if you have a File with some text, probably the best thing to do is to create a new BufferedReader(new FileReader(file)) BufferedReader is nice because you can read one line at a time using readLine(). BUT, there's a glitch here, which is that doing it that way doesn't set you specify how text in the file was actually encoded. So what you really need to do is: new BufferedReader(new InputStreamReader(new FileInputStream(file), "utf-8")) Hope that helps.
2 of 5
7
InputStream implementations read raw bytes from some source (a file, a network socket, etc). Sometimes that's all you need. Reader implementations read characters of text instead, translating them from whatever character encoding is used by the source into the UTF-16 character encoding that Java itself uses. Most Readers have to be told which character encoding to translate from. Many InputStream and Reader implementations are actually wrappers for another InputStream/Reader that enhance it in some way. For example, InputStreamReader takes the raw bytes of an InputStream and decodes them into characters as a Reader. Some specific classes of note: FileInputStream reads raw bytes from a file. It does nothing else, just that. FileReader reads characters from a file, in the platform's default character encoding. Use this if you want to read a plain text file on the user's computer. Don't use this for plain text files downloaded from the Internet or transferred from another operating system, as they are fairly likely to be in a different character encoding; for those, you need to figure out the correct encoding and then use InputStreamReader, below. InputStreamReader takes an InputStream (which reads bytes) and gives you a Reader (which reads characters). Use this if you already have an InputStream that you need to read characters from, or if you need to read a text file with a character encoding other than the platform's default (e.g. downloaded from the Internet or transferred from another operating system). BufferedInputStream / BufferedReader maintain a buffer, which can improve performance under some circumstances for reasons I won't go into. Basically, if you find yourself reading one byte/character at a time, you should probably use a BufferedInputStream/BufferedReader to avoid the performance hit this would otherwise cause. BufferedReader also lets you read a full line of text, rather than reading individual characters, if you need to do that.
๐ŸŒ
All About Circuits
forum.allaboutcircuits.com โ€บ home โ€บ forums โ€บ embedded & programming โ€บ programming & languages
Java - Reading from a Socket using a BufferedReader object | All About Circuits
December 3, 2014 - Example 1: ... import java.io.*; class Reader{ public static void main(String[] args){ int lineCount = 0; try { File myFile = new File("Reader.java"); FileReader fileReader = new FileReader(myFile); BufferedReader reader = new BufferedReader(fileReader); String line = null; // *** My question is about the next line **/ while( (line = reader.readLine()) != null ) { System.out.println(++lineCount + " " + line); } reader.close(); } catch (Exception ex) { ex.printStackTrace(); } System.out.println("lineCount = " + lineCount); } }
๐ŸŒ
Programiz
programiz.com โ€บ java-programming โ€บ filereader
Java FileReader (With Examples)
However, since Java 11 we can specify the type of character encoding (UTF-8 or UTF-16) in the file as well. FileReader input = new FileReader(String file, Charset cs); Here, we have used the Charset class to specify the character encoding of the file reader. The FileReader class provides ...
๐ŸŒ
W3Schools
w3schools.com โ€บ java โ€บ java_user_input.asp
Java User Input (Scanner class)
If you don't know what a package is, read our Java Packages Tutorial. In the example above, we used the nextLine() method, which is used to read Strings.
๐ŸŒ
Jenkov
jenkov.com โ€บ tutorials โ€บ java-io โ€บ readers-writers.html
Java IO: Readers and Writers
September 4, 2015 - Just like with streams, Reader's and Writer's can be combined into chains to achieve more interesting IO. It works just like combining the Reader with InputStream's or the Writer with OutputStream's. For instance, you can achieve buffering by wrapping a Reader in a BufferedReader, or a Writer in a BufferedWriter. Here are two such examples: