I have a tar file and which contains many files. I need to get a specific file from tar file and read data from that file.
I am untaring file using the below code and I will read this returned input stream using some other function.
private InputStream unTar(final File inputFile, final File outputDir) throws FileNotFoundException, IOException, ArchiveException {
InputStream versionInputStream = null;
final InputStream is = new FileInputStream(inputFile);
final TarArchiveInputStream debInputStream = (TarArchiveInputStream) new ArchiveStreamFactory().createArchiveInputStream("tar", is);
TarArchiveEntry entry = null;
while ((entry = (TarArchiveEntry)debInputStream.getNextEntry()) != null) {
if (!entry.isDirectory() && entry.getName().equals("version.txt")) {
versionInputStream = new FileInputStream(entry.getFile());
}
}
return versionInputStream;
}
I get null pointer exception when i do versionInputStream = new FileInputStream(entry.getFile());
I know that we can first save this file in directory and then read the file but i dont want to save this file in directory.
Is there some way I can read this file without saving the file to some dir?