how to read file using InputStreamReader in java

how to read file using InputStreamReader in java

Hi,

I want to learn to use the InputStreamReader class of Java and trying to read a text file with the class.

how to read file using InputStreamReader in java?

Thanks

View Answers

July 20, 2020 at 12:57 PM

Hi,

This is example code:

package my.code;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;

public class InputStreamReaderExample {

    public static void main(String[] args) throws FileNotFoundException, IOException {
        //File to Read
        String fileName = "data.txt";
        //Get BufferedReader for reading file
        try (BufferedReader br = new BufferedReader(new InputStreamReader(
                new FileInputStream(fileName), StandardCharsets.UTF_8))) {

            String line;
            //Read all lines of file
            while ((line = br.readLine()) != null) {
                //Print on console
                System.out.println(line);
            }
        }

    }

}

Thanks









Related Tutorials/Questions & Answers:
how to read file using InputStreamReader in java
how to read file using InputStreamReader in java  Hi, I want to learn to use the InputStreamReader class of Java and trying to read a text file with the class. how to read file using InputStreamReader in java? Thanks  
how to read and write an xml file using java
how to read and write an xml file using java  Hi Can anyone help me how to read and write an xml file which has CData using java
Advertisements
How to read the data in text file seperated by by ',' in java using IO Operations
How to read the data in text file seperated by by ',' in java using IO Operations  in Text file data like raju 45,56,67 ramu 46,65,78 raji 34,23,56 this is the student marks in text file.this data read and calculate
how to read file line by line using filereader in java
how to read file line by line using filereader in java  Hi, how to read file line by line using filereader in java? Thanks   Hi, This is example code: package my.code; import java.io.BufferedReader; import
How to Read a file line by line using BufferedReader?
How to Read a file line by line using BufferedReader?  Hello Java... problem is to find the best way to read the file in Java. I just searched the google... to Read a file line by line using BufferedReader, efficiently and using less memory
To read & write a excel file using the core java
To read & write a excel file using the core java  Hai, I'm new to JavaProgram.But now i need java program to read & write a excel file so, can anyone help me to learn the above mentioned topic(link for the portion
read XML file and display it using java servlets
read XML file and display it using java servlets  sir, i can't access Xml which is present in my d drive plz can u should go through my code n tell me the things where i went wrong java servlet program protected void
How to Read a File in Java
How to Read a File in Java? In this section we are going to know, How to read a file in Java. We have to follow three step to read a File. First get... is the program to read a file in Java. import java.io.*; public class FileRead
How to Read Excel file Using Java
How to Read Excel file In this section,you will learn how to read excel file... and every cell and stored the excel file values into the vector.This Vector data is then used to display file values on the console. Here is the code
How to read file in java
How to read file in java Java provides IO package to perform reading and writing operations with a file. In this section you will learn how to read a text... to read file in Java?" Another way of reading a file: The another
read and write a file using javascript
read and write a file using javascript  How to read and write a file using javascript
How To Read File In Java
How To Read File In Java In this section we will discuss about about how data of a file can be read in Java. A file can contain data as bytes, characters..._TO_REPLACE_1 Example This example demonstrates that how to read a file in java
Java Read .doc file using POI library
Java Read .doc file using POI library In this section, you will learn how to read the word document file using POI library. The class HWPFDocument throw all of the Word file data and the class WordExtractor extract the text from
How To Read File In Java with BufferedReader
How To Read File In Java with BufferedReader class - example code This tutorial shows you how you can read file using BufferedReader class in your program... class: import java.io.*; /** * How To Read File In Java with BufferedReader
How to read properties file in java
How to read properties file in java Description of Example:- In this example... is the video tutorial of: "How to read properties file in Java?" How we... of Read properties file in java import java.io.*; import java.util.Properties
How to read the .doc/ .docx file in Java Program
How to read the .doc/ .docx file in Java Program  Hi, I am beginner in Java programming language. Can anybody explain How to read .doc file in Java.... This way you can read the .doc or .docx file in Java programming language. Thanks
how to read a text file with scanner in java
how to read a text file with scanner in java  Hi, I am looking for the example code in Java for reading text file line by line using the Scanner class. how to read a text file with scanner in java? Thanks   Hi
How to Read file line by line in Java program
by line in Java. But there are various ways that can help read a larger file... of read file line by line in Java is printed on console.ADS_TO_REPLACE_5 Example of Read file line by line using BufferReader: package ReadFile; import
How to read value from xml using java?
How to read value from xml using java?  Hi All, I want to read value from following xml using java.. In <Line>,data is in format of key and value pair.. i want to read only values..could u plz help me in this?Thanks
How to read an eml file? - Java Beginners
How to read an eml file?  Hello dears, now i want to read en eml file stored in a folder. is it possible to use the same code for reading a txt file? or do i have to use javamail api? Thanks Spalax
How to read properties file in Java?
a property file in Java: "How to read properties file in Java?" ADS... the java.util.Properties class for reading a property file in Java program... to value. The java.util.Properties class is used to read the properties file
Java read file
There are many ways to read a file in Java. DataInputStream class is used to read text File line by line. BufferedReader is also used to read a file in Java...(in)); readline() is used to read the next line. Example of Java Read File:ADS_TO_REPLACE_3
How to read big file line by line in java?
Learn how to write a program in java for reading big text file line by line In this tutorial I will explain you how you can read big file line by line... to read the big file in your java program. For example you have to process some
How to check if a file is read-only in java
How to check if a file is read-only in java A read-only file is any file... will not be able to make changes to it. You can make a file read-only by using... to check read only file: Java API provides the functions to find if any file
write a program in java to read a text file and write the output to an excel file using filereader and filewriter?
write a program in java to read a text file and write the output to an excel file using filereader and filewriter?  write a program in java to read a text file and write the output to an excel file using filereader and filewriter
java read file
java read file  Hello i need some help... i want to read an MS Excel file in java so how to read that file
Read file in java
Read file in java  Hi, How to Read file in java? Thanks   Hi, Read complete tutorial with example at Read file in java. Thanks
Read Specific Line from file Using Java
Read Specific Line from file Using Java Here we are going to read a specific line from the text file. For this we have created a for loop to read lines 1 to 10 from the text file. If the loop reached fifth line, the br.readLine() method
read from file and store using hash map
read from file and store using hash map  I was stuck with a java project where I have to read a file with two different concepts and store them differently in hashmap. My data file would be something like Adults: Name, xyz
Read from file java
Read from file java  How to Read from file java? What is the best method for a text file having a size of 10GB. Since i have to process the file one line at a time so tell me the very best method. Thank you
Java read binary file
Java read binary file  I want Java read binary file example code... at Reading binary file into byte array in Java. Thanks   Hi, There is many more examples at Java File - Learn how to handle files in Java with Examples
Java IO InputStreamReader
Java IO InputStreamReader In this section we will discuss about the InputStreamReader in Java. java.io.InputStreamReader class takes input as a byte... to conversion of these bytes to characters. read() method in InputStreamReader
Read XML using Java
of all i need to read xml using java . i did good research in google and came to know that there are many ways to read using different API like SAX, DOM , XOM Jar...Read XML using Java  Hi All, Good Morning, I have been working
read xml using java
read xml using java  <p>to read multiple attributes..."\interface type=""\level="0"\source_file="ppp" etc as wise each attribute n... to other interacting modules, as communication is only allowed to take place using
How to read a rows which have a values in a excel file using apache poi - JSP-Servlet
How to read a rows which have a values in a excel file using apache poi  Dear sir, How to read excel file in that only a rows which are having some values using apache poi...please help me sir. Thanks and Regards
how to read data from excel file through browse and insert into oracle database using jsp or oracle???
how to read data from excel file through browse and insert into oracle database using jsp or oracle???  sir.. i have number of excel sheets which...://www.roseindia.net/answers/viewqa/JSP-Servlet/28123-write-excel-file-into-the-oracle
how to read this xml file - XML
how to read this xml file  i want to read this xml file using java(using struts2 or using jsp) and i want result as name=admin menu=user... read i have tried lot more , but i am not able to read this xml file
How to read properties file in Python using configparser?
How to read properties file in Python using configparser and printing.... Following example shows you how to read the properties file in Python very easily.... Now we can proceed for developing the program to read properties file using
Java Read File Line by Line - Java Tutorial
to reading file in Java How to Read Excel file Using Java Read Specific Line from file Using Java How to read... how to read a text file in Java one line at a time: Video Tutorial
how to read text file with java 8 stream api
how to read text file with java 8 stream api  Hi, I want to use Java... code. how to read text file with java 8 stream api? Thanks   Hi, Following example is for reading text file line by line in Java using the stream api
How do I read a large file quickly in Java?
How do I read a large file quickly in Java?  Hi, I my project I have... in 1-2 GB in size. What is the best way to read the file efficiently? How do I read a large file quickly in Java? Thanks   Hi, You can't read the whole
How to read a large text file line by line in java?
How to read a large text file line by line in java?  I have been assigned a work to read big text file and extract the data and save into database... you kind advice and let's know how to read a large text file line by line in java
How to make a file read-only in java
How to make a file read-only in java A read-only file is any file... a file read-only by using file.setReadOnly() method of File class. After using... program will make a the file read onlyADS_TO_REPLACE_1 To make file read only
How can i read a file from nth line onwards in java
How can i read a file from nth line onwards in java  Hi, I need to read a file content from its nth line onwards till end. How can i implement it in java. Regards, Chinnu
How to read yahoo mail using java mail api - WebSevices
How to read yahoo mail using java mail api  Hi there .... i wanted to know how to read mail from yahoo using pure java code. Is there any one who can help me regarding this, please if possible show me the exact way as well
JDOM example in java, How to read a xml file in java.
JDOM example in java, How to read a xml file in java. In this tutorial, we will see how to  read a xml file in java. Code. Student.xml...;File(data);       DOMBuilder builder 
How to check a file is read-able or not in java
Description: This example demonstrate how to check a file have read permission... check for its read property of a file. As in the file path we see '\'... or false depends on the file have read property at the specified path that is set
How to read text file in Servlets
How to read text file in Servlets  ... from the disk file. The InputStreamReader class is used to read the file.... Read the file line by line using the while loop  ((text = reader.readLine
Java read properties file
Java read properties file In this section, you will learn how to read... Video tutorial of reading properties file in Java: "How to read... using the properties file. In the properties file, data has been stored as a key
How to open a file in java using JFileChooser
How to open a file in java using JFileChooser  How to open a file in java using JFileChooser

Ads