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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:03:32+00:00 2026-05-29T08:03:32+00:00

I am in the process of making a program, which allows you to view

  • 0

I am in the process of making a program, which allows you to view your file system.
I was testing it, and ran into a problem: It was saying a directory called “Documents and Settings” was on my C:\ drive, while it wasn’t there.

This is how I get my file array:

File f = new File(path); //path being a path sent by the client, for example C:\
            if(f.isFile()){
                //TODO start downloading it.
                out.println("ERR: no dir!");
                return;
            }
            Server.log.log("System path requested: " + f.getAbsolutePath());
            File[] files = f.listFiles();
            for(int i = 0; i < files.length; i++){
                File found = files[i];
                if(!found.exists()){
                    continue;
                }
                if(found.isDirectory()){
                    out.println("dir:" + found.getName());
                }else{
                    out.println(found.getName());
                }
                System.out.println("Printed " + found.getName());
            }
            out.println("ENDOFLIST"); //Notify the client it has to stop receiving data

For some reason, this outputs quite a lot of directories that I can’t seem to find, even with the “Show hidden folders” option on.

When trying to access these directories, it tries to read the contents of the directory, but since the directory doesn’t exist it throws an exception, causing no data to get sent over sockets and my client freezing.

My question is: Is there a way to either check if the file/directory REALLY exists? Note, if you look at my code block, if the file/dir doesn’t exist it already continues instead of writing it to the socket.

I’ve given it a google, but no matches were found. Also, I’ve given the search function a go, but it didn’t come up with anything similar.

  • 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-29T08:03:34+00:00Added an answer on May 29, 2026 at 8:03 am

    I suggest to use the new Fil I/O API introduced by Java 7, it features greatly improved support of the features a specific file system offers. It also offers the possibility to use walk the file tree.

    Have a look at the FileVisitor http://docs.oracle.com/javase/7/docs/api/java/nio/file/FileVisitor.html that will greatly help you.

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

Sidebar

Related Questions

I am making a simple program which suppose to accept txt file data from
I am searching a library or jar file for making a system monitoring program.
I'm in the process of making a simple drawing program for the iPhone. At
I'm making a C Assessment Program through Java, which has a bunch of programming
I'm making a program which opens a configured application after with the passed paramters
Best reader, I'm stuck on one of my concepts. I'm making a program which
I'm running a multi-threaded C program (process?) , making use of semaphores & pthreads.
In the process of making an old webpage standard compliant, the validator came across
I'm in the process of making my PHP site Unicode-aware. I'm wondering if anyone
I am in the process of making a website that involves a shopping cart.

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.