"Constructor FileReader in class filereader.FileReader cannot be applied to given types"

filereader, java

Solution

Use the fully qualified class name `java.io.FileReader` since you have a class already called `FileReader` when calling a `BufferedReader`, like so:

BufferedReader reader = new BufferedReader(new java.io.FileReader(inFile));

Without fully qualifying your `FileReader` (or specifying imports), the compiler will use your declared `FileReader`.

Problem

first time post here. I am in the process of writing a Java program that takes an input text file, reads the contents, and then prints them to the screen and also creates an output file with the contents. I have set up the necessary writers, but when I try to use `BufferedReader readername = new BufferedReader(new FileReader(inFile));` it gives me the error in the title. Any ideas what's causing it? Here's the code. ``` public class FileReader { public static void main(String[] args) throws IOException { try { File inFile = new File("inputText.txt"); BufferedReader reader = new BufferedReader(new FileReader(inFile)); String line = null; BufferedWriter writer = new BufferedWriter(new FileWriter("Contents.txt")); while ((line=reader.readLine()) != null) { writer.write(line); System.out.println("File 'Contents.txt' successfully written"); System.out.println(line); } } catch (IOException e) { System.out.println(e); } } } ```

Original source