Results 1 to 6 of 6
  1. #1
    Java_Newbie_1 is offline Member
    Join Date
    May 2012
    Posts
    2
    Rep Power
    0

    Default Directory Listing Always giving Null on Windows 7

    Hi Java Forums,

    I'm a beginner programmer and was having an issue with some simple code. I am trying to get the list of files within a specific folder.

    The code works perfectly on an existing Windows XP machine I tried, however on my Windows 7 PC it doesn't work and it always is null. I'm very confused because on both computers the Folder and files exists so as far as I can tell the only difference is the Operating System (And the version of Eclipse, but since this is such simply code I would assume it has nothing to do with Eclipse. The One returning null is running the Android ADK as well).

    I'm wondering if Windows 7 has some security or something that blocks the Java (Using Eclipse) from seeing the directory? The user I'm logged in with has all access to the folder I'm looking at so I'm unsure why this is occurring.

    The code is simply:

    File dir = new File("C:\\Test\\");
    String[] list = dir.list();

    Windows XP - I receive a list array full of the documents
    Windows 7 - I receive null

    Any help would be appreciated, I have been messing around for a few days and can't figure it out sadly :( Thanks ahead of time.
    Last edited by Java_Newbie_1; 05-10-2012 at 02:50 AM.

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default Re: Directory Listing Always giving Null on Windows 7

    You could read the bug list to see if there are any known issues of your version of Java on Windows 7. You could also try using a single forward slash instead of the double backslash in the directory path.

  3. #3
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    757
    Rep Power
    7

    Default Re: Directory Listing Always giving Null on Windows 7

    When you don't have access it should throw a SecurityException exception. Are you sure that the path is exist on your C drive?

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: Directory Listing Always giving Null on Windows 7

    Check dir.exists() and dir.isDirectory()

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    Java_Newbie_1 is offline Member
    Join Date
    May 2012
    Posts
    2
    Rep Power
    0

    Default Re: Directory Listing Always giving Null on Windows 7

    Hey, thanks for the replies. Through a bit more troubleshooting I know its something to do with the android development and not java. I was able to get it working when it was a java project instead of an android project.

    Not sure how familar people are with android app development here, but it has something to do with the android emulator or something.

    Sorry about leading this in the wrong direction initially. I appreciate the help and ill try to research this problem more since I know a little more of the cause of the problem now. Thanks for the help. Hopefully it will be easier for me to research with this new information

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: Directory Listing Always giving Null on Windows 7

    Quote Originally Posted by Java_Newbie_1 View Post
    Not sure how familar people are with android app development here, but it has something to do with the android emulator or something.
    I'm moving this thread to the Android section. In future, please don't post Android questions in New to Java.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. listing files of directory and subdirectory
    By oulutas in forum New To Java
    Replies: 10
    Last Post: 10-10-2010, 05:48 PM
  2. Listing directory contents
    By gandalf5166 in forum New To Java
    Replies: 8
    Last Post: 05-02-2010, 12:41 AM
  3. JSP/Ajax/Post giving null values
    By Mange in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 04-22-2010, 10:02 PM
  4. Replies: 8
    Last Post: 11-20-2009, 09:33 PM
  5. Listing file system from root directory
    By Java Tip in forum Java Tip
    Replies: 1
    Last Post: 04-18-2009, 10:03 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •