code: public static void createFileWithSparse(String filePath, long length) throws IOException {
      Path path = Paths.get(filePath);
      try {
        Files.deleteIfExists(path);
        try (
            SeekableByteChannel channel = Files.newByteChannel(path, StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE, StandardOpenOption.SPARSE)
        ) {
          channel.position(length - 1);
          channel.write(ByteBuffer.wrap(new byte[]{0}));
        }
      } catch (IOException e) {
        throw new IOException("create spares file fail,path:" + filePath + " length:" + length, e);
      }
    }
docs: 创建指定大小的Sparse File