String separator = File.separator;
String filename = "myfile.txt";
String dir = "mydir1"+separator+"mydir2";
File f = new File(dir,filename);
if(f.exists()){
System.out.println("文件名:"+f.getAbsolutePath());
System.out.println("文件大小:"+f.length());
}else{
f.getParentFile().mkdirs();
try {
f.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
FileWriter writer;
try {
writer = new FileWriter(f, true);
writer.write("xxxxxxxx");
writer.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
转载于:https://www.cnblogs.com/oraclespace/p/3983431.html