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.
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.
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?
Re: Directory Listing Always giving Null on Windows 7
Check dir.exists() and dir.isDirectory()
db
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
Re: Directory Listing Always giving Null on Windows 7
Quote:
Originally Posted by
Java_Newbie_1
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