Independentsoft
Any library, any programming language
Home
Purchase
Support
Company
Contact
JCompound
>
Tutorial
> Create file
The following example shows you how to create simple compound file with two streams.
import java.io.IOException; import java.nio.charset.Charset; import com.independentsoft.io.structuredstorage.CompoundFile; import com.independentsoft.io.structuredstorage.Stream; public class Example { public static void main(String[] args) { try { CompoundFile file = new CompoundFile(); Charset charset = Charset.forName("UTF-8"); byte[] descriptionBuffer = charset.encode("File description").array(); byte[] dataBuffer = new byte[100000]; Stream descriptionStream = new Stream("description", descriptionBuffer); Stream dataStream = new Stream("data", dataBuffer); file.getRoot().getDirectoryEntries().add(descriptionStream); file.getRoot().getDirectoryEntries().add(dataStream); file.save("c:\\temp\\file.bin", true); } catch (IOException e) { e.printStackTrace(); } } }