
课程咨询: 400-996-5531 / 投诉建议: 400-111-8989
认真做教育 专心促就业
昆明达内的小编这一期给大家讲向*.txt文档里面重复添加同一个字符串。
用代码写五万个对不起。
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 = "xxx,我错啦~";
String url = "G:\\sorry.txt";
WriteToFile(sorry , url);
}
}
了解详情请登陆昆明达内IT培训官网(km.tedu.cn)!