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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:48:37+00:00 2026-05-28T16:48:37+00:00

In Java, I am trying to list the files and folders in my C:\

  • 0

In Java, I am trying to list the files and folders in my C:\ directory and loop through them using:
File[] files = new File("C:\\").listFiles();

However, to my surprise when I loop through the array I find that the first index is C:\Documents and Settings! For a starters, I’m running Windows 7 Home Premium and I haven’t even upgraded from Windows XP or anything but no matter what I do I can not see this folder on my drive, dispite choosing to view hidden folders!?

Furthermore, as you would suspect, when you start to use a recursive method to look through every folder on the drive it throws a NullPointerException as soon as it tries to list the files in that directory.

Does anyone know why this is, or even better how to solve the issue? Any idea’s appreciated, thanks in advance


UPDATE: I’ve now very quickly established that C:\Documents and Settiings is a symlink or “JUNCTION”, so know by question is: how do I determine that it is a symlink in Java so that I can tell the for loop to skip any?

  • 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-28T16:48:38+00:00Added an answer on May 28, 2026 at 4:48 pm

    Ok I think this warrants a full answer here. There are several things going on at once here which makes it a bit more interesting than on first glance.

    Yes Documents and Settings is a symlink under Vista+, no that’s not the problem we have here. The real problem is that the folder has some extremely restricted access rights – by default not even Admins have access to it.

    If we read the isSymbolicLink javadoc it clearly states:

    false if […] cannot be determined if the file is a symbolic
    link or not

    Since we don’t have any rights to access the directory we cannot determine whether it is a symbolic link or not. But since we then try to access the file anyhow we get an exception telling us we can’t access the file.

    Hence the correct check should look something like this:

    if (!Files.isReadable(file) || Files.isSymbolicLink(file)) continue;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was trying to get a list of files under a directory using: val
I'm trying to implement my own List system in Java. the List class file
I am trying to implement a Stack in java (using the list interface: Interface
I am new to Java and am trying to run a program using Eclipse.
Flex front-end using AMF to Java back. Trying to read, in real-time, a file
I'm trying to go deep into Dictionary ADT and Skip List for Java. My
I'm currently trying to construct a list of bean classes in Java from a
I am trying to output some Java objects as JSON, they have List properties
I am just trying to understand the extends keyword in Java Generics. List<? extends
I am a complete JSP beginner. I am trying to use a java.util.List in

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.