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 8884579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:05:39+00:00 2026-06-14T21:05:39+00:00

This should be a really simple question but Google + my code isn’t working

  • 0

This should be a really simple question but Google + my code isn’t working out.

In Eclipse on Windows, I want my program to look inside a certain folder. The folder is directly inside the Project folder, on the same level as .settings, bin, src, etc. My folder is called surveys, and that’s the one I want my File object to point at.

I don’t want to specify the full path because I want this to run on both of my computers. Just the path immediately inside my Project.

I’m trying this code but it isn’t working – names[] is coming back null. And yes I have some folders and test junk inside surveys.

File file = new File("/surveys");
    String[] names = file.list();

    for(String name : names)
    {
        if (new File("/surveys/" + name).isDirectory())
        {
            System.out.println(name);
        }
    }

I’m sure my mistake is within the String I’m passing to File, but I’m not sure what’s wrong?

  • 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-14T21:05:41+00:00Added an answer on June 14, 2026 at 9:05 pm

    In your question you didn’t specify what platform you are running on. On non-Windows, a leading slash signifies an absolute path. Best to remove the leading slash. Try this:

    File file = new File("surveys");
    System.out.println("user.dir=" + System.getProperty("user.dir"));
    System.out.println("file is at: " + file.getCanonicalPath());
    String[] names = file.list();
    
    for(String name : names)
    {
        if (new File(file, name).isDirectory())
        {
            System.out.println(name);
        }
    }
    

    Make sure the in your run configuration, the program is running from the projects directory (user.dir = <projects>)

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

Sidebar

Related Questions

This should be a really simple question, but I'm still having difficulty. I have
This should be really really simple, but for whatever reason... String line; String question
I know this question should be really simple, but for some reason thoroughly understanding
I know that this is a really simple question, but where should I place
This should be simple but nothing's working: Question How do you set the height
This should be really simple, but I have tried many solutions posted on the
This seems like it should be really simple, but I'm unable to figure this
This is probably a really simple question but I can't seem to find anything
This is maybe a really simple question, but I couldn't locate an answer: For
I know this isn't a straightforward question but I would really appreciate some feedback

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.