人生苦短

python

f = open('d:/python.txt', 'w')
for i in range(10000, 9999999):
    f.write(str(i)+'\n')
f.close()

java

public static void main(String[] args) {
        int start = 10000;
        int end = 999999;
        int period = 10000;
        String tmp = "";
        String file = "d:/java.txt";
        FileWriter fw = null;
        try {
            fw = new FileWriter(file);
            for (int i = start; i < end; i++) {
                tmp += i + "\n";
                if (i % period == 0) {
                    // 寫文件
                    fw.write(tmp);
                    tmp = "";
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (fw != null) {
                try {
                    fw.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章