Java tutorial
//package com.java2s; import java.io.DataOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; public class Main { private static void writeNonEmptyFile(final File file) { try { final OutputStream outputStream = new DataOutputStream(new FileOutputStream(file)); final int expectedLength = 10; outputStream.write(expectedLength); // The negative beginning index is to accommodate the header. Fancy. Ever so fancy. for (int i = -3; i < expectedLength; i++) outputStream.write(0x0); outputStream.close(); } catch (final IOException e) { throw new RuntimeException("Exception trying to create non-empty file!", e); } } }