Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Strange folder names returned in Desktop directory using java.io.File

807569Jun 13 2006 — edited Jun 14 2006
I have a static method which returns an array of objects which are the "root" files of the system the program is running on.

I have had to recently change the method from using:
   File[] files=File.listRoots();
to
   File[] files = FileSystemView.getFileSystemView().getRoots
as on some computers running windows, the File.listRoots() method will bring up a dialog window asking for a disc to be inserted into the floppy drive... even if there is no floppy drive present.

The FileSystemView.getFileSystemView().getRoots() method returns the desktop directory under windows and thus stops this annoying request for a disc.

However, as seen here: http://www.geocities.com/budgetanime/fileSystemViewScreenShot.txt

The "My Network Neighbourhood" and "My Computer" 'folders' are representy by some sort of hash instead of their readable names. Does anyone know how to retrieve these readable names?

As seen in the code below, i am using File.getName() to obtain the name of the file(folder).
    public static LocalFile getRoot()
    {
        //File[] files=File.listRoots();
    	    	
    	File[] files = FileSystemView.getFileSystemView().getRoots();
        
        LocalFile lf=new LocalFile();
        
        
        lf.childrenNodes=new LocalFile[files.length];
        
        for (int i=0;i<files.length;i++)
        {
        	lf.childrenNodes=new LocalFile(files[i],true);
}
return lf;
}


This method is called via a constructor.
    
    private void init(File file,boolean isRootDrive)
    {
        if (isRootDrive) dir=true;
        else dir=file.isDirectory();

        id=new HashKey(Scan.getFileID(file.getName(),file.length()),16);
        
        name=file.getName();
        if (name.equals("")) name=file.getPath();

        this.file=file;
        File parent=file.getParentFile();
        if (parent!=null)
        {
            path=parent.getPath();
            
            if (path==null)
            {
                System.out.println("");
            }
        }
        else path="";
        System.out.println(path);
    }
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 12 2006
Added on Jun 13 2006
6 comments
209 views