java 生成随机数 写入文件中

public static void writeTxt(String path,String p){
File file=new File(path);

try {
if(!file.exists()) file.createNewFile();
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
for(long k=0;k<1000000000;k++){
long l = (long)(Math.random()*1000000000);
String s = ""+l;
int i = s.length();
for(int j=0;j <9-i;j++){
s = "0"+s;
}
System.out.println(s);
writer.write(s);
writer.newLine();
}

writer.flush();
writer.close();

} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}

你可能感兴趣的:(java)