閨蜜說讓我用代碼寫五萬個對不起給她~~ ...
閨蜜說讓我用代碼寫五萬個對不起給她~~
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); } }