I am using JDK 7 and I am trying to perform a simple write-to-file operation with the following code:
import java.io.BufferedWriter;
import java.io.FileWriter; // JAVA says this is conflicting...why?
FileWriter fw = new FileWriter("hello.txt");
BufferedWriter bw = new BufferedWriter(fw); // JAVA says this is an error and asks me to convert FileWriter to type Writer.
I am using JDK 7 and this is how I’ve always written to a file in Java, but this is the first in JDK 7, and it is not working.
Could someone please explain why?
The only reason I can think of is that you have a class called FileWriter in the same package as the class, from which you’ve copied the code fragments. In that case, you are not allowed to import a FileWriter class from a different package, but have to use the qualified name (java.io.FileWriter) in the code itself.