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?

Recommended Answers

All 4 Replies

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

Why would it be safer? I mean what's the risk?

Java is multi-platform, so you can't assume that the OS will support files >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);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.