This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Defragmentation / File Position" Watch "Defragmentation / File Position" New topic
Author

Defragmentation / File Position

Lambert Stein
Greenhorn

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
Wanderer
Sheriff

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: 14074
    
  16

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 7 API documentation
Scala Notes - My blog about Scala
Saverio Miroddi
Greenhorn

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

Look at this page:

http://www.microsoft.com/technet/sysinternals/information/diskdefragmenting.mspx

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

Bye!
Saverio M.


Using a text editor for programming.
 
Consider Paul's rocket mass heater.
 
subject: Defragmentation / File Position
 
Similar Threads
WA #1.....word association
help needed on writie/read to/from specific position in the file
Checking EOF with raf.readShort()
xml node insert
skip() method of InputStream???