I tried different methods like:
InputStream inStream = new FileInputStream(fileName);
while (inStream.available() > 0)
{
System.out.println(inStream.read());
}
inStream.close();
However, this too gave the same message as stated in the subject.
I even tried adding checking for new line and printing per line.
Or even using System.out.print instead, but that gave the error "Too few lines".
I am not sure what I am doing wrong.
package com.codegym.task.task13.task1318;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.FileNotFoundException;
import java.lang.NullPointerException;
/*
Reading a file
*/
public class Solution {
public static void main(String[] args) {
// write your code here
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String fileName = reader.readLine();
FileInputStream fileStream = new FileInputStream(fileName);
BufferedReader br = new BufferedReader(new InputStreamReader(fileStream));
String line = br.readLine();
while(line != null) {
System.out.println(line);
}
reader.close();
fileStream.close();
br.close();
} catch (FileNotFoundException e) {
} catch(IOException e) {
} catch (NullPointerException e) {
}
}
}