how to read file using InputStreamReader in java

Ads
 

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

Ads









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 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 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... can be very inefficient. Example Here is the program to read a file in Java
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
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 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... java.io.*; /** * How To Read File In Java with BufferedReader class
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 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
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.... Example This example demonstrates that how to read a file in java. To read a file
How to read properties file in java
How to read properties file in java Description of Example:- In this example... of: "How to read properties file in Java?" How we will create...= 8285279608 Example of Read properties file in java import java.io.
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 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 Read file line by line in Java program
by line in Java. But there are various ways that can help read a larger file...()?. The output of read file line by line in Java is printed on console. Example of Read file line by line using BufferReader: package ReadFile; import
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 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... file: Java API provides the functions to find if any file is read only
How to read properties file in Java?
. Here is the video tutorial of reading a property file in Java: "How to read properties file in Java?" Here is the data.properties the properties... the java.util.Properties class for reading a property file in Java program
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 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
How to transfer a file in java using SSH & Telnet
How to transfer a file in java using SSH & Telnet  How to transfer a file in java using SSH & Telnet
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
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
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
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
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
how to create an excel file using java
how to create an excel file using java  how to create an excel file using java
Java Read File Line by Line - Java Tutorial
. Here is the video tutorial that explains you how to read a text file in Java... How To Read File In Java with BufferedReader... Best way to reading file in Java How to Read
how to create pdf file using java and itextjar
how to create pdf file using java and itextjar  How to create pdf file having paragraphs and alignments done using java and itextjar 5.10 version.? hope i get quick response
how to create pdf file using java and itextjar
how to create pdf file using java and itextjar  How to create pdf file having paragraphs and alignments done using java and itextjar 5.10 version.? hope i get quick response
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...(); method is used. In the page you learned how to make a file read only

Ads