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

rossryanAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mick BarryJava DeveloperCommented:
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
Become a Microsoft Certified Solutions Expert

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).

Mick BarryJava DeveloperCommented:
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
Mick BarryJava DeveloperCommented:
get some sleep :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.