io 流 txt本地生成
public static void main(String[] args) {
text("E://logs", "一个txt", "一段话");
}
public static void text(String path, String title, String content) {
try {
File mkdirsName = new File(path);
if (!mkdirsName.exists()) {
mkdirsName.mkdirs();
}
File writename = new File(path + "\\" + title + ".txt");
if (!writename.exists()) {
writename.createNewFile();
} else {
String osName = System.getProperties().getProperty("os.name");
if (osName.equals("Linux")) {
content = "\r" + content;
} else {
content = "\r\n" + content;
}
}
BufferedWriter out = new BufferedWriter(new FileWriter(writename, true));
out.write(content);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}