user3117081
user3117081

Reputation: 91

File Not Found Exception, Identical Directory Exists

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

Answers (3)

Masudul
Masudul

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

Dhan
Dhan

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

hari
hari

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

Related Questions