import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
public class Test {
public static void main(String[] args) throws IOException {
//判断n是不是质数。
//数学原理:
File file = new File("D:\\shu.txt");
FileOutputStream fileOutputStream = new FileOutputStream(file);
//建立缓冲输出字节流对象
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(fileOutputStream);
//查找10000内的质数
for(int num = 2;num<10000;num+=1){
boolean flag = true;
for(int i = 2;i<=Math.sqrt(num);i++){
if(num%i==0) {
flag = false;
}
}
if(flag){//是质数就写到硬盘
String s = num+",";
//把数据写出
bufferedOutputStream.write(s.getBytes());
//把缓冲数组中内部的数据写到硬盘上面。
bufferedOutputStream.flush();
}
}
bufferedOutputStream.close();
}
}