Consider the code:
File file = new File(\"c:\\\\temp\\\\java\\\\testfile\");
testfile is a file, and it may or may not exist.
testfile
File filePath=new File("your_file_path"); String dir=""; if (filePath.isDirectory()) { dir=filePath.getAbsolutePath(); } else { dir=filePath.getAbsolutePath().replaceAll(filePath.getName(), ""); }