Create a fixed-length fileTag(s): IO


//
// usage : java CreateAFile 2048 twokbytes.dat
//
import java.io.FileOutputStream;
import java.io.IOException;

public class CreateAFile {
    public static void main(String[] args) throws IOException {
        byte[] buf = new byte[8192];
        long n = Long.parseLong(args[0]);
        FileOutputStream fos = new FileOutputStream(args[1]);
        long m = n / buf.length;
        for (long i = 0; i < m; i++) {
            fos.write(buf, 0, buf.length);
        }
        fos.write(buf, 0, (int)(n % buf.length));
        fos.close();
    }
}

blog comments powered by Disqus