-3

My code currently use RandomAccessFile to read a ZIP file. The code is taken from a open source

project. I need to make RANDOM Access File operation in memory without creating a physical File in

the disk. So need to replace functionality of RandomAccess File with FileOutput Stream.

The way Random Access File object Create.

protected RandomAccessFile file;

public ExtRandomAccessFile(File zipFile) throws IOException {
this.file = new RandomAccessFile(zipFile, "r");
}

Usage access different position mapped to the Random Access File

int censig = raFile.readInt( fileOffset );
short fileNameLength = raFile.readShort( fileOffset + 28 );
short extraFieldLength = raFile.readShort( fileOffset + 30 );
long fileOffsetPos = fileOffset + 28 + 14;
long fileDataOffset = raFile.readInt( fileOffsetPos );
int locsig = raFile.readInt( fileDataOffset );

Please advice me how do I replace my code with FileOutputstream. What is the

mechanism I should use to look up for values.

Thanks

user3693532
  • 51
  • 1
  • 3

1 Answers1

0

You can use a DataOutputStream to read different values. But be careful, because java always uses big endian format. If you don't do this for educational reasons, I would recommend ZipOutputStream to create zip files.

kaetzacoatl
  • 1,329
  • 14
  • 26