The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
October 2001



This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.


Using the list method in the File class

Posted by Hiran Watson on October 08, 2001 at 11:26 PM

Hi, I'm trying to use the list method in the File class for a program I'm writing. The way my program works is that I have a method which takes a user-chosen directory and lists all the files and directories in that parent directory. I then return the list to my main method. I know that the list method returns an array of strings, so I use an array of strings in my main method and in my private method. But I get gobbledgook when I print out the list. Can anyone plse help me? Thanks in advance. Here is an example of my code:
//main method
String[] b = new String[] {}
b = userFile.listFiles(); //listFiles is my private method
String[] p = new String[] {}
File q = new File(userChosenFile) //userChosenFile is the directory path that the user specifies (ex. c:\windows\)
p = q.list();
return p;
Like I said, when I print b, I get some gobbledygook which shouldn't happen. Thanks again for the help.


Sponsored Links

Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us