Check if file exists without creating it

后端 未结 4 1932
花落未央
花落未央 2020-12-03 05:05

If I do this:

File f = new File(\"c:\\\\text.txt\");

if (f.exists()) {
    System.out.println(\"File exists\");
} else {
    System.out.println(\"File not f         


        
4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-03 05:31

    Creating a File instance does not create a file on the file system, so the posted code will do what you require.

提交回复
热议问题