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
  • 168,117
  • 40
  • 217
  • 433

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,079
  • 11
  • 23
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
  • 168,117
  • 40
  • 217
  • 433
Sahil Bhalla
  • 175
  • 1
  • 4