Code example for RandomAccessFile

Methods: closesetLength

0
     */ 
    public static File generateFile(int size) {
        File file = new File("./test" + "//" + getFileName(size));
 
        try { 
            RandomAccessFile raf = new RandomAccessFile(file, "rw");
            raf.setLength(1024 * size);
            raf.close();
 
        } catch (IOException e) {
            e.printStackTrace();
        } 
 
        return file;
    } 
 
    private static String getFileName(int size) {
        String unit = "KB";
 
        if (size < 1024 * 1024)
Stop searching for code, let great code find you!  Add Codota to your java IDE