package com.why;
import java.io.BufferedOutputStream; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream;
public class Test { public static final int KB = 1024; public static final int DEFAULT_BUFFER_SIZE = 8 * KB;
public static void main(String[] args) throws IOException {
for (int aa = 0; aa < 100; aa++) { final int x = aa; new Thread() { public void run() { File f = new File("d:\\aaaa.txt");
OutputStream out = null;
try { out = new BufferedOutputStream(new FileOutputStream(f)); } catch (FileNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); }
byte[] buffer = new byte[DEFAULT_BUFFER_SIZE]; for (int i = 0; i < buffer.length; i++) { buffer[i] = (byte) x; } for (int i = 0; i < 100; i++) { try { out.write(buffer, 0, buffer.length); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } }
try { out.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("结束"+x); } }.start(); }
try { Thread.sleep(1000000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); }
}
}
结果类似这样: AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA BB BB BB BB BB BB BB BB BB BB BB BB BB BB BB BB BB BB BB BB BB BB BB BB BB BB BB CC CC CC CC CC CC CC CC CC CC CC CC CC CC CC CC CC CC CC CC CC CC CC CC CC CC CC
|