Link to home
Start Free TrialLog in
Avatar of sarahchi
sarahchi

asked on

how to get directory and file name easily?

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!
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

See

f.getName();
f.getPath();
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sarahchi
sarahchi

ASKER

both returns f to me:
f.getName();
f.getPath();

I don't know what they really do?
String s = "/some/directory/file.name";
File f = new File(string);
then use the methods in the File class to access what you need

thanks, but what is " abstract pathname"?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
:-)