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);
}
}
}
Use the fully qualified class name
java.io.FileReadersince you have a class already calledFileReaderwhen calling aBufferedReader, like so:Without fully qualifying your
FileReader(or specifying imports), the compiler will use your declaredFileReader.