Home » Java » Not able to access file in eclipse gives : FileNotFoundException

Not able to access file in eclipse gives : FileNotFoundException

Posted by: admin June 30, 2018 Leave a comment

Questions:

In eclipse i am trying to give path of one configuration.json file but it is not taking it .

System.getProperty("user.dir") 

gives C:\Users\cmalik\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Eclipse
and

try {
            File f = new File("."); // current directory

            File[] files = f.listFiles();
            for (File file : files) {
                if (file.isDirectory()) {
                    System.out.print("directory:");
                } else {
                    System.out.print("     file:");
                }
                System.out.println(file.getCanonicalPath());
        }

gives

file:C:\Users\cm\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Eclipse\Eclipse Jee Neon.lnk
file:C:\Users\cm\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Eclipse\hs_err_pid10180.log
file:C:\Users\cm\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Eclipse\hs_err_pid9728.log

And my project structure is

ProjectName
  ---src
      ---- com.abc.def.ghi.jkl.WebServices
                              ------ myService.java
  ---configuration.json

I tried code for accessing file is :

FileReader file = new FileReader("configuration.json");
or
FileReader file = new FileReader("projectName\configuration.json");  

It is not able to access as output for System.getProperty(“user.dir”) is eclipse folder not my current projectName folder.
How can i get my files please let me know.

Answers: