Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a sparse file in Java on NTFS

Tags:

java

windows

nio

This command should create a sparse file:

channel = Files.newByteChannel(path, EnumSet.of(CREATE,WRITE,SPARSE));

However, it just creates a regular (non-sparse) file. I can manually turn it into a sparse file using fsutil on the command line, but how can I get the Java Runtime to do this?

I am using Java 11 on Windows 10 (NTFS).

like image 850
Tony the Pony Avatar asked May 09 '26 13:05

Tony the Pony


1 Answers

Apparently, creating a sparse file only works with OpenOption CREATE_NEW (which replaces any existing file), but not with CREATE (which only creates the file if it doesn't exist).

channel = Files.newByteChannel(path, EnumSet.of(CREATE_NEW,WRITE,SPARSE));
like image 171
Tony the Pony Avatar answered May 12 '26 03:05

Tony the Pony