首页 > 编程语言 > 详细

【Java】向*.txt文档里面重复添加同一个字符串

时间:2017-02-10 20:30:39      阅读:124      评论:0      收藏:0      [点我收藏+]

闺蜜说让我用代码写五万个对不起给她~~

import java.io.FileWriter;
import java.io.IOException;

/**
 * Created by lenovo on 2017/1/22.
 * 1.常量字符串"对不起"
 * 2.循环判定条件,五万字,使用count计数
 * 3.创建文本文件并写入
 */
public class SorryForHui
{
    public static void WriteToFile(String str , String url)
    {
        int count = 0;
        try
        {
            FileWriter writer = new FileWriter(url,true);
            while(count<50000){
                writer.write(str);
                count++;
            }
            writer.close();
        }catch(IOException e)
        {
            e.printStackTrace();
        }
    }
    public static void main(String[] args)
    {
        String sorry = "傻慧慧,我错啦~";
        String url = "G:\\sorry.txt";
        WriteToFile(sorry , url);
    }
}

技术分享

【Java】向*.txt文档里面重复添加同一个字符串

原文:http://www.cnblogs.com/bolumiere/p/6387695.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!