• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 398
  • Last Modified:

File Path, FIle Chooser, etc.

Right, I'm slowly losing my sanity over Swing and Java, but not yet.

My question is simple. How do I get the real path for a File object?

When I say real, I mean "C:\Users\Ryan\My Documents\MyFile.xml". Need the drive letter and everything. I've called path and absolutepath, but get "" nothing for the path. I get the filename just fine, but not the path....


Thanks,
Ryan

File newFile = jFileChooser_Evaluation.getSelectedFile();
        if(!newFile.exists()){
            return;
        }

String path = newFile.getAbsolutePath();

Open in new window

0
rossryan
Asked:
rossryan
  • 3
  • 2
2 Solutions
 
robthewolfCommented:
this looks ok, it should look fine when you do System.out.println(path);
can you show me the rest of your code where you print it?
0
 
objectsCommented:
try getCanonicalPath()
0
 
rossryanAuthor Commented:
Right, I'm retarded. I was calling the setPath for one of my classes after I called the Load method, which was screwing it up something ridiculous.

Right, then. For the win, how do I grab just the path for the directory, not the file? I.e. "C:\DIrectory\Directory\Directory\"?

Using any of the FIle.GetPath methods are giving me the filename in addition to the directory path.


Thanks,
Ryan
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
objectsCommented:
getParent()
0
 
rossryanAuthor Commented:
RIght, it's 5:21 AM where I am, it's becoming increasingly obvious I've been up for too long.

Thanks,
Ryan
0
 
objectsCommented:
get some sleep :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now