我是靠谱客的博主 魔幻时光,这篇文章主要介绍Java文件操作:以追加的方式输出文本,现在分享给大家,希望可以做个参考。


// 以追加的方式将文本输出到本地文件中
public static void writeTextAppendLocalFile(String localFilePath, String content) {
File file = new File(localFilePath);
file.mkdir();
file = new File(localFilePath + "\java-input-file.txt");
FileOutputStream fos = null;
OutputStreamWriter osw = null;
try {
if (!file.exists()) {
boolean hasFile = file.createNewFile();
if (hasFile) {
// System.out.println("file not exists, create new file");
}
fos = new FileOutputStream(file);
} else {
// System.out.println("file exists");
fos = new FileOutputStream(file, true);
}
osw = new OutputStreamWriter(fos, "utf-8");
osw.write(content);
osw.write("rn");
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (osw != null) {
osw.close();
}
} catch (IOException e) {
e.printStackTrace();
}
try {
if (fos != null) {
fos.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}

最后

以上就是魔幻时光最近收集整理的关于Java文件操作:以追加的方式输出文本的全部内容,更多相关Java文件操作:以追加内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(125)

评论列表共有 0 条评论

立即
投稿
返回
顶部