import java.io.File;
/**
* Created by duanhongbo on 2016/5/8.
*/
public class FileDemo {
public static void main(String[] args) {
File f = null;
File f1 = null;
String v;
boolean bool = false;
try{
// create new file
f = new File("D:\\fhb\\test\\" +"dhb" ,"dhb"+".xml");
f.mkdirs();
// returns abstract parent pathname
f1 = f.getParentFile();
// absolute path from abstract pathname
v = f1.getAbsolutePath();
System.out.print("Parent file path: "+ f1);
System.out.print("Parent file path: "+v);
// true if the file path exists
bool = f.exists();
// if file exists
if(bool)
{
// prints
// System.out.print("Parent file path: "+ f1);
// System.out.print("Parent file path: "+v);
}
}catch(Exception e){
// if any error occurs
e.printStackTrace();
}
}
}
输出结果为:
Parent file path: D:\fhb\test\dhb
Parent file path: D:\fhb\test\dhb