Alternative to File.exists() in Java

后端 未结 6 1383
没有蜡笔的小新
没有蜡笔的小新 2020-12-06 07:14

I never thought it would happen to me, but I ran into my first bug in Java:

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5003595

I\'m pretty much in th

6条回答
  •  佛祖请我去吃肉
    2020-12-06 07:39

    The obvious alternative is File.isFile(). Try that first.

    Although it will become inaccurate when reading read-only files you could always use the File.canWrite() to check if the file exists.

    If both the above fail you could use the File.length(). If it returns 0L you know that the file does not exists.

提交回复
热议问题