在写文件流时, 在已有内容的 test.txt 文件里追加文字时, 老是把旧的文件内容删除掉,怎样实现在已有内容的 test.txt 文件里再追加文字呢? 如下代码怎样修改呢? import java.io.FileOutputStream;
public class FileStream
{
public static void main(String[] args)
{
String str = "test message!!!";
try
{
FileOutputStream out = new FileOutputStream("test.txt");
out.write(str.getBytes());
out.flush(); out.close();
}
catch (Exception e)
{ }
}
}
public class FileStream
{
public static void main(String[] args)
{
String str = "test message!!!";
try
{
FileOutputStream out = new FileOutputStream("test.txt");
out.write(str.getBytes());
out.flush(); out.close();
}
catch (Exception e)
{ }
}
}
解决方案 »
- 这是为什么呢?
- 新手求问
- JFrame中的一些小问题!求大虾们帮帮忙啊
- 请教有关qq邀请多人聊天的技术
- 可以在eclipse运行的程序打包后 使用一些功能就会报错
- 问个java数组比较的问题
- AudioData data = as.getData();
- 我用DefaultMutableTreeNode建立jtree的节点,但空的目录显示为小圆点,如何才能显示为目录呢?
- 搞了3小时都不出来。高分相送(jar文件出错)急~~~~~~~
- Applet程序如何在运行时使一个panel控件自动执行鼠标双击事件?
- 各位高手帮我解决一下JAVA里把时间转换成像YYYY-MM-DD这样的形式!!!
- FCKeditor在weblogic7配置问题?弄了两天还不行!!!555555555555555
改为:
FileOutputStream out = new FileOutputStream("test.txt",true);
设置追加模式为真