File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes I/O and Streams and the fly likes Defragmentation / File Position Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Defragmentation / File Position" Watch "Defragmentation / File Position" New topic

Defragmentation / File Position

Lambert Stein

Joined: Oct 30, 2006
Posts: 14
Is it possible to access a file in Java directly?
I want to change its position on the disk like a defragmenting application.
If not, is there any free external dll or exe which does this?
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
I'm pretty sure there's no way to do this using pure Java, at least. No idea what existing DLLs or EXE's might be most useful to you here, sorry.

"I'm not back." - Bill Harding, Twister
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15101

This is not possible with pure Java. What you want to do is get low-level access to the file system. Different operating systems use very different file systems (Windows: FAT, NTFS; Linux: ext2, ext3, reiserfs, ..., etc.) and all these file systems store data on disk in a different way.

If you want to write a defragmenting program for a specific OS and a specific file system, you'll need to know a lot about the details of that file system, and what the most efficient way is to lay out files on disk for that particular file system. It will not be a trivial program to write.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Saverio Miroddi

Joined: Jun 16, 2006
Posts: 21
NT Systems have APIs for defragementing files!

Look at this page:

however, i think using JNI would be quite a pain in the ***!

Saverio M.

Using a text editor for programming.
I agree. Here's the link:
subject: Defragmentation / File Position
It's not a secret anymore!