Consider the code:
File file = new File("c:\temp\java\testfile");
testfile
is a file, and it may or may not exist.
I want to get the directory c:\temp\java\
using the File
object. How do I go about doing this?
Consider the code:
File file = new File("c:\temp\java\testfile");
testfile
is a file, and it may or may not exist.
I want to get the directory c:\temp\java\
using the File
object. How do I go about doing this?
In either case, I'd expect file.getParent()
(or file.getParentFile()
) to give you what you want.
Additionally, if you want to find out whether the original File
does exist and is a directory, then exists()
and isDirectory()
are what you're after.