先看题:http://home.cnblogs.com/group/topic/61189.html
我想了一下 应该有两种方法一个一边循环一边写入;另一个循环换之后在写入,当然效率而言后者肯定要高
这里只为大家提供的第二种
package outputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
/**
* @author szh
* @email cjhszh@126.com
*/
public class FileDemo {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
String file = "F:/t2.txt";
int j=0;
String str = "";
FileOutputStream fos = new FileOutputStream(file, true);
for (int i =100; i < 201; i++) {
if (i%3==0) {
j++;
String str1 = String.valueOf(i);
str = str +" "+str1;
if(j%10==0){
System.out.println("==========="+j);
str=str+"\r\n";
}
}
}
byte [] b = str.getBytes();
fos.write(b);
fos.close();
}
}
不知道大家还有没有别的办法?