import java.io.*;
public class FileTest {
public static void main(String[] args) {
String s = new String();
String s1 = new String();
try {
File ff = new File("E:/temp");
if (ff.isDirectory()){
System.out.print("目录存在");
} else {
ff.mkdirs();
System.out.print("目录创建成功");
}
// true表示在文件末尾追加内容
FileWriter writer = new FileWriter(filepath, true);
s1 = "加入内容 \r\n";
output.write(s1);
output.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
本文提供了一个使用Java进行文件及目录操作的示例程序。该程序演示了如何检查指定路径是否存在,若不存在则创建目录,并向文件中追加写入内容。
951

被折叠的 条评论
为什么被折叠?



