[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

how to get directory and file name easily?

Posted on 2006-03-27
9
Medium Priority
?
294 Views
Last Modified: 2010-03-31
Hi,

I have a String which includes both directory name and file name, I could not find a simple function to break the string into direcoty name and file name. I tried


File file = new File(Name);// name includes both path and file name
then I used different get function from File class, but always got the whole string for the directory name, please help!
0
Comment
Question by:sarahchi
  • 4
  • 3
  • 2
9 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 16303985
See

f.getName();
f.getPath();
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 240 total points
ID: 16304012
And of course

f.getParent();

(directory)
0
 

Author Comment

by:sarahchi
ID: 16304264
both returns f to me:
f.getName();
f.getPath();

I don't know what they really do?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 92

Expert Comment

by:objects
ID: 16304513
String s = "/some/directory/file.name";
File f = new File(string);
then use the methods in the File class to access what you need

0
 

Author Comment

by:sarahchi
ID: 16304884
thanks, but what is " abstract pathname"?
0
 
LVL 92

Assisted Solution

by:objects
objects earned 160 total points
ID: 16304960
Its java representation of the path to account for OS differences.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16323521
:-)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month18 days, 18 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question