创建文件夹
fPath="F:"+File.separator+"tomcat6work"+File.separator+"nihao1";
public static void getFileExists(String fPath) {
File file = new File(fPath);// 如果文件夹不存在则创建
if (!file.exists() && !file.isDirectory()) {
file.mkdir();
}
}
//文件写入txt
public static void createTxt(String filePath, String content, boolean b) {
String str = new String(); // 原有txt内容
String s1 = new String();// 内容更新
try {
File f = new File(filePath);
if (!f.exists()) {
f.createNewFile();// 不存在则创建
}
if (false == b) {
BufferedReader input = new BufferedReader(new FileReader(f));
while ((str = input.readLine()) != null) {
s1 += str + "\n";
}
System.out.println(s1);
input.close();
}
s1 += content;
BufferedWriter output = new BufferedWriter(new FileWriter(f));
output.write(s1);
output.close();
} catch (Exception e) {
e.printStackTrace();
}
}