Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5849441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:59:59+00:00 2026-05-22T12:59:59+00:00

The old, more or less deprecated java.io.File API had a method exists which returned

  • 0

The old, more or less deprecated java.io.File API had a method exists which returned true if the File pointed to an existing one in the file system, but I couldn’t find any comparable method for java.nio.file.Path:

scala> import java.nio.file._
import java.nio.file._

scala> val path = Paths.get("/foo")
path: java.nio.file.Path = /foo

scala> path.
asInstanceOf     compareTo        endsWith         getFileName      getFileSystem    getName          getNameCount     
getParent        getRoot          isAbsolute       isInstanceOf     iterator         normalize        register         
relativize       resolve          resolveSibling   startsWith       subpath          toAbsolutePath   toFile           
toRealPath       toString         toUri  

Of course I could just convert the path back to a File but I guess there is a better way to do that.

Edit: OK, thanks to everyone pointing out Files.exists. Does someone know why it got more complicated (than having a simple exists method on Path)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T13:00:00+00:00Added an answer on May 22, 2026 at 1:00 pm

    Use the Files class:

    Files.exists(path);

    EDIT: to answer your subsequent question, I think the reason that the method is in another class is that Path is an interface, and they wanted to provide an implementation (similar to putting sorting methods in the Collections class instead of the List interface).

    Not directly related to the question, but as per ratchet freak there is an optional varags argument to the method as well, which determines how symbolic links are handled

    Read the Javadocs from Oracle here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having more or less converted a lot of old Tk scripts over to Tkx
I've just upgraded some old Java source which has been running on a Sun
I have an old .dot file with a few dozen styles in it. I
I'm trying to clean up some warnings in some old Java code (in Eclipse),
An old Direct3D book says ...you can achieve an acceptable frame rate with hardware
I have inherited an old crusty PHP application , and I'd like to refactor
I need debug some old code that uses a Hashtable to store response from
I've got an old, legacy VB6 application that uses the DHTML editing control as
Back in the old days, Help was not trivial but possible: generate some funky
I have a old website that generate its own RSS everytime a new post

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.