Hi,

I need to write a program which can decrease the free disk space. For eg, if the free disk space is 5GB, the application should ask the user how much space do you want occupy. Application should take the input eg, 2GB and decrease the disk space to 3GB.

Does anyone have any suggestions on how this can be implemented. Can we create a text file of the size specified by the user?

Can we create a text file of the size specified by the user?

Yes. Just ask for the size and write that number of bytes to a new file. For large amounts of space it may be safer to create a new directory and fill that with 1GB files, rather than have one file > 2GB

I am only going to use the application for windows. Anyways, I've written the code which works for me:

        BufferedWriter writer = null;
        File file = new File("C:\\DecreaseFreeDiskSpace.txt");
        FileSystemView fsv = FileSystemView.getFileSystemView();
        File[] roots = File.listRoots();
        RandomAccessFile f = new RandomAccessFile(file, "rw");
        int kb = 1024;
        int mb = 1024*1024;
        int gb = 1024*1024*1024;
        double userInput = 57;
        double setSize = userInput *(gb);
        f.setLength((long) setSize);
This question has already been answered. Start a new discussion instead.