我試圖在文件中打印132_000行。使用Java在文件中打印132000行
這裏是我的代碼:
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Random;
import java.util.Scanner;
public class CredentialTemplate {
public static void main(String[] args) throws IOException {
// Declaring output file
File fout = new File(
"D:\\testout.txt");
FileOutputStream fos = new FileOutputStream(fout);
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos));
int start = 0, stop = 0;
Scanner x = new Scanner(System.in);
System.out.print("Start: ");
start = x.nextInt();
System.out.print("End: ");
stop = x.nextInt();
Random r = new Random();
for (int i = start; i <= stop; i++) {
System.out.println("Importeduser" + i + ",Test,4," + r.nextInt(9)
+ r.nextInt(9) + r.nextInt(9) + r.nextInt(9) + r.nextInt(9)+ r.nextInt(9)+",0,"
+ r.nextInt(9) + r.nextInt(9) + r.nextInt(9) + r.nextInt(9)
+ r.nextInt(9) + r.nextInt(9) + r.nextInt(9) + r.nextInt(9)
+ r.nextInt(9) + r.nextInt(9));
bw.write("Importeduser" + i + ",Test,4," + r.nextInt(9)
+ r.nextInt(9) + r.nextInt(9) + r.nextInt(9) + r.nextInt(9)+ r.nextInt(9)+",0,"
+ r.nextInt(9) + r.nextInt(9) + r.nextInt(9) + r.nextInt(9)
+ r.nextInt(9) + r.nextInt(9) + r.nextInt(9) + r.nextInt(9)
+ r.nextInt(9) + r.nextInt(9));
bw.newLine();
}
}
}
問題我面對: 我沒有得到的txt文件,所有1,32,000線。 有時它的1,3169行或1,31721行。
但在控制檯中,我能夠看到所有1,320,000個印刷品。
請讓我知道如果我在這裏做錯了什麼。
在此先感謝。
嘗試退出前沖洗緩衝的作家:) – folkol 2015-04-06 11:26:28