How to list the files in current directory?

前端 未结 7 2118
傲寒
傲寒 2021-02-05 01:05

I want to be able to list the files in the current directory. I\'ve made something that should work but doesn\'t return all the file names.

File dir = new File(\         


        
7条回答
  •  一整个雨季
    2021-02-05 01:47

    Your code gives expected result,if you compile and run your code standalone(from commandline). As in eclipse for each project by default working directory is project directory that's why you are getting this result.

    You can set user.dir property in java as:

       System.setProperty("user.dir", "absolute path of src folder");
    

    then it will give expected result.

提交回复
热议问题