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

  • SEARCH
  • Home
  • 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 8654991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:55:22+00:00 2026-06-12T14:55:22+00:00

I am fairly new to java and I am trying to find if the

  • 0

I am fairly new to java and I am trying to find if the file specified in the LINUX path exists.

private void validateFilePath(String filePath) {

        File dir = new File(filePath);

        if(dir.exists()){
                System.out.println("File exists in the path " + dir);
                setTARGET_IMG_DIR("filePath");
                return; 
        }else{
            System.out.println("File does not exists in the path: " + dir);
            return;
        }

    }

The dir.exists works fine if I give a absolute path from my root like this

/Users/yv/Documents/Eclipse-workspace/InputParser/bin/test.txt

but if I give a relative path like
test.txt or /InputParser/bin/test.txt it says files does not exists.

I am planing on creating a jar of this projects and hence this should work with both relative path(files in the same directory) and absolute path from the root. How can I handle this ?

Is it possible to search for the absolute path of that file from the root and append it to the file name ?

  • 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-06-12T14:55:24+00:00Added an answer on June 12, 2026 at 2:55 pm

    Eclipse typically runs with the project directory set as the user.dir, that is the base directory for execution. So if the absolute path is:

    /Users/yv/Documents/Eclipse-workspace/InputParser/bin/test.txt
    

    Then the relative path will be:

    bin/test.txt
    

    You can double check the working directory by getting the user.dir property from Java’s system properties. For more information on Java’s system properties check the documentation.

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

Sidebar

Related Questions

I am fairly new to Java, and I am trying to construct a very
I find myself a little baffled here. I'm fairly new to android/java development so
I'm fairly new to Java and I've been trying to put a JFreeChart in
I'm fairly new to Java and I'm trying to create a GUI application with
I'm fairly new to Java. Currently trying to have the filename given in args[]
I'm a fairly competent Java programmer who's very new to C. I am trying
I'm fairly new to Java and Android programming in general but I would like
I'm still fairly new to Java, but I'm fairly sure this shouldn't happen. There's
I am fairly new to Java, and recently I was reading some material about
I'm fairly new to Java and am writing an app that needs an XML

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.