UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Java - Getting Directory Returns Wrong Directory    
 
   
kruuth
post Aug 6 2015, 08:46 AM
Post#1



Posts: 849
Joined: 30-May 07



When I run this it will not return the right directory:

CODE
public String pullDirectory(){
        //System.out.println(directoryListing.getText());
        String dirString = ".";
        JFileChooser chooser = new JFileChooser();
        chooser.setCurrentDirectory(new java.io.File("."));
        chooser.setDialogTitle("Choose Source Directory");
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        chooser.setAcceptAllFileFilterUsed(false);
        if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
            dirString = chooser.getCurrentDirectory().toString();
            }
        else {
            dirString = "No Selection ";
            }
        return dirString;      
    }


When I do this, the browsing window will open, but if I navigate to something like "C:\Lists" it will return only C:. If I navigate to something like "C:\Users\Bob\Desktop" it will only return "C:\Users\Bob"

I'm a little new to JAVA. How do I fix this?
Go to the top of the page
 
kruuth
post Aug 6 2015, 01:35 PM
Post#2



Posts: 849
Joined: 30-May 07



Fixed it. Needed to add the chooser.getSelectedFile() to the end...makes no sense to me but it fixes the problem.
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    17th December 2017 - 10:44 AM