Henry Wong wrote:Please explain what you mean by a defragger.
An application that defragments a hard disk.
First of all, Java doesn't provide an API that allows you to do direct sector reads and writes to the hard disk, so you should seriously consider using something else. You can access the OS libraries that does this via JNI, or you can access the /dev devices that allow you such access -- but again, it is probably much easier to just use C/C++, which can directly access these libraries.
And you have other issues...
1. "fragments" and hence, "defragging" is format specific. There is a world of difference between UFS, NTFS, FAT, and the tons of hard disk formats out there. Some has more fragging issues that others; some will actually defrag automatically with usage; some are actually designed well with some fragging; etc. etc. You defragger will behave differently with all of these hard disk formats.
2. The FS may actually be using the disk while you are defragging it (if the disk is mounted), so you need to make sure that you don't crash the file system driver, and hence the OS while you are doing this. To compound this, if the data is important, it wouild be a good idea to not test it on that drive first. This complexity increasing again, if you are trying to defrag the disk which your OS booted from.