import java.io.*; import java.nio.*; import java.nio.channels.*; public class ThreadTest extends Thread { private static int num = 0; private FileChannel fc; private ThreadTest(FileChannel fc) { num++; this.fc = fc; } public void start() { byte[] b; ByteBuffer bb; while(true) { try { b = new StringBuilder("Thread number: ").append(Integer.toString(num)).toString().getBytes(); bb = ByteBuffer.allocate(b.length); bb.put(b); fc.write(bb); } catch(IOException ioe) { ioe.printStackTrace(); } } } public static void main(String[] args) { FileOutputStream fo = null; try { File f = new File("test.txt"); f.createNewFile(); //Won't do anything if it doesn't exist. fo = new FileOutputStream(f); FileChannel fc = fo.getChannel(); for(int i=0; i