Link to home
Create AccountLog 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
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
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
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
:-)