Read file using FileReader:
- import java.io.File;
- import java.io.FileReader;
- public class ReadFileByFileReader {
- public static void main(String[] args) {
- try {
- File file = new File("D:\\data.txt");
- FileReader fr = new FileReader(file);
- int length = (int) file.length();
- char c[] = new char[length];
- fr.read(c);
- String data = new String(c);
- System.out.println(data);
- fr.close();
- } catch (Exception e) {
- System.out.println("excepton occured in " + e);
- }
- }
- }
Output:
Hi guys !!
This is Ishaan from India.
and I'm reading the data from a text file line by line using BufferedReader.
Isn't it interesting !! to read the data from a file line by line
irrespective of amount of data that a file is having.
No comments:
Post a Comment