Reputation: 91
However the file appears to be there. Under FileOne.txt's properties the directory is listed as; C:\Users\Rig\Desktop\Java
The code is as follows,
import java.io.File;
import java.util.Scanner;
class Parse{
public static void main(String args[]){
System.out.println("Hey gurl hey World!");
File file = new File("C:\\Users\\Rig\\Desktop\\Java\\FileOne.txt");
Scanner input = new Scanner(file);
while(input.hasNext()) {
String nextToken = input.next();
System.out.println("Hey gurl hey World!");
}
input.close();
}
}
Any help or insight would be appreciated!
Edit: This issue has been resolved, consult Masud's answer.
Upvotes: 1
Views: 69
Reputation: 21981
If your path is correct than you should read your file. But, you need to catch or throw FileNotFoundException
to compile or run.
public static void main(String args[]) throws FileNotFoundException{
.....
}
Upvotes: 2
Reputation: 42
The issue seems to be your FileName is FileOne.Txt and the whole file name is FileOne.Txt.txt including textpad extension. So the whole path will be C:\Users\Rig\Desktop\Java\FileOne.Txt.txt
Upvotes: 0
Reputation: 1963
you wrongly typed the file type txt instead you give Txt.
File file = new File("C:\\Users\\Rig\\Desktop\\Java\\FileOne.txt");
Upvotes: 0