A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© che201311 中级黑马   /  2013-11-23 16:52  /  969 人查看  /  1 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

1
2
3
4
5
6
7
8
9
10
11
12
13
14
public static void write(Word word) throws Exception{
         
        File file = new File("tokenOut.txt");
         
        if(!file.exists()){
            
            System.out.println("file not exist!");
        }else{
            
            DataOutputStream out = new DataOutputStream(new FileOutputStream(file));
            System.out.println("--->" + word.getMessage());
            out.writeUTF(new String(word.getMessage().getBytes(), "UTF-8"));
        }
    }
中的out.writeUTF(new String(word.getMessage().getBytes(), "UTF-8"));
每次都把前面写的覆盖了,怎么办?

评分

参与人数 1技术分 +1 收起 理由
FFF + 1 淡定

查看全部评分

1 个回复

倒序浏览
DataOutputStream out = new DataOutputStream(new FileOutputStream(file, true));
new FileOutputStream(file, true));加个true吧应该
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马