Skip to Main Content

Java Development Tools

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

java.io.File.isInvalid() in jdk1.8.0_45 bugged?

Tracy SafranAug 31 2015 — edited Sep 1 2015

I was using the  (new File(fileLoc).isFile())  method to determine if a file I needed to read in actually existed.  I tested on a file I knew was there and it returned invalid.  I traced through the code to see if maybe I was entering the path wrong and I found this in the java.io.File class:

    final boolean isInvalid() {

        if (status == null) {

            status = (this.path.indexOf('\u0000') < 0) ? PathStatus.CHECKED

                                                       : PathStatus.INVALID;

        }

        return status == PathStatus.INVALID;

    }

Am I crazy or will this always return an INVALID?  I haven't had the chance to check newer versions.  If this isn't the right way to check file existence, what should I use?

Thanks,

Tracy

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 29 2015
Added on Aug 31 2015
1 comment
2,343 views