java将文本写入本地硬盘

注意:首先要在E盘创建qaz.txt文本文件。然后执行代码写入。

public static void main(String[] args) {

SecurityCodeUtils scu = new SecurityCodeUtils();

String content="";

for (int i = 0; i < 10000; i++) {

content= content+scu.createBatchNo()+(int)((Math.random()*9+1)*1000)+"\r\n";

}

try {

// String content = "测试使用字符串";

File file = new File("E:/qaz.txt");

if(file.exists()){

FileWriter fw = new FileWriter(file,false);

BufferedWriter bw = new BufferedWriter(fw);

bw.write(content);

bw.close(); fw.close();

System.out.println("test1 done!");

}

} catch (Exception e) {

// TODO: handle exception

}

}