public static boolean updateFile(String str)
{
str = "test";
boolean blg = false;
try {
BufferedWriter bw = new BufferedWriter(new FileWriter("C://data.txt"));
StringBuilder sb = new StringBuilder("");
sb.append(str);
String a = sb.toString();
byte[] b = (a).getBytes();
// 写入文件,还可以用其他方法如:write(String str)
bw.write(a, 0, b.length);
bw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return blg ;
}
java操作将内容写入文件
最新推荐文章于 2025-04-04 02:59:25 发布
本文提供了一个使用Java进行文件更新的示例代码。该代码通过BufferedWriter将指定字符串写入到本地文件中,并展示了如何处理可能遇到的IOException。尽管示例中的函数返回值未被利用,但整体流程展示了基本的文件操作技巧。
1万+

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



