自己编程中遇到写入txt,
try {
File file = new File("D:\\text1.txt");FileOutputStream fs = new FileOutputStream(file);
PrintStream p = new PrintStream(fs);
p.println(strlist);
} catch (Exception e) {
// TODO: handle exception
}
不用去管是否存在文件,没有会自动创建。不过strlist是一次性写入的,不能一行一行写入。所以需要我们事先存储好相关的内容。