i’m trying to read text from a text file that I have in my computer in drive D:
So, I wrote in Java:
public class Test {
public static void main(String [] args ) throws IOException{
FileReader in= new FileReader("D:\nir");
BufferedReader bin= new BufferedReader(in);
String text = bin.readLine();
}
}
I’m getting this error exception:
Exception in thread "main" java.io.FileNotFoundException: D:ir
(The filename, directory name, or volume label syntax is incorrect)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileReader.<init>(Unknown Source)
at A11.main(A11.java:14)
I don’t understand what is wrong, since the file exist, the name is correct, perhaps I don’t use the correct syntax and commands?
I think, you should first check if file is exists or not. Also use: D:\\file.txt