Dear CodeGym Members,
like other users, I am also getting "Program display too many lines". Will it possible for you to check what am I doing wrong here? I tested with a file and it's working fine.
package com.codegym.task.task13.task1318;
import java.io.*;
/*
Reading a file
1. Read a file name from the console.
2. Display the contents of the file in the console (on the screen).
3. Don't forget to free up resources. Close the streams for file input and keyboard input.
Requirements:
1. The program must read the file name from the console.
2. The program must display the contents of the file.
3. You must close the file input stream (FileInputStream).
4. The BufferedReader must also be closed.
*/
public class Solution {
public static void main(String[] args) throws IOException {
// write your code here
BufferedReader readerFileName=null;
FileInputStream fileInputStream=null;
BufferedInputStream bufferedInputStream=null;
try {
System.out.println("Enter the file name");
readerFileName = new BufferedReader(new InputStreamReader(System.in));
String fileName = readerFileName.readLine();
fileInputStream = new FileInputStream(fileName);
bufferedInputStream = new BufferedInputStream(fileInputStream);
int c;
while((c=bufferedInputStream.read())!=-1){
System.out.print((char)c);
}
}
finally {
readerFileName.close();
fileInputStream.close();
bufferedInputStream.close();
}
}
}