0

I tried to read a file using the java.io.File class but it was throwing filenotfound exception. But the file is there and when I use the exists method it returns false

public static void main(String[]args){
    File file = new File("q.txt");
    Scanner fileScanner = new Scanner(file);
}
Andrew Thompson
  • 166,747
  • 40
  • 210
  • 420

3 Answers3

0

Please provide the complete path in the File constructor

public static void main(String[]args){
    File file = new File("Please provide complete path here");
    Scanner fileScanner = new Scanner(file);
}
Debapriya Biswas
  • 1,011
  • 9
  • 20
0

Make sure that the file is under the project folder and not in the package folder.

0

You are trying to provide the relative path to the file by providing the filename.

Please provide the absolute path of the file . For e.g.

File f = new File("C:\\Hello\\AnotherFolder\\The File Name.PDF");  
Andrew Thompson
  • 166,747
  • 40
  • 210
  • 420
Sahil Bhalla
  • 167
  • 1
  • 4