I wrote this code without using the BufferedReader (as I actually wasn't told to do so). But, according to the validator, I still have to close it.... So, should I use it instead of the Scanner or the InputStream? I'm slightly puzzled;)
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.InputStream;
import java.io.IOException;
/*
Reading a file
*/
public class Solution {
public static void main(String[] args) throws IOException {
Scanner console = new Scanner(System.in);
String fileName = console.nextLine();
//InputStream inStream = new FileInputStream("c:/source.txt");
InputStream in = new FileInputStream(fileName);
/*
while (inStream.available() > 0)
{
int data = inStream.read(); //read one byte from the input stream
outStream.write(data); //write that byte to the other stream.
}
*/
while (in.available() > 0) {
int data = in.read();
System.out.print((char) data);
}
in.close();
console.close();
}
}