I'm trying to return a list of file names from inside of a tar file. I'm using the code below, but when it gets to the while loop, it immediately goes to the catch exception and says "java.io.IOException: Error detected parsing the header
Below is the code I'm using. Can you help me figure out why this doesn't work?
public List<String> getFilesInTar(String filename) {
List<String> foundFiles = Lists.newArrayList();
String filePath = System.getProperty("user.home") + File.separator + "Downloads" + File.separator + filename;
try {
TarArchiveInputStream tarInput = new TarArchiveInputStream(new FileInputStream(filePath));
TarArchiveEntry entry;
while ((entry = tarInput.getNextTarEntry()) != null) {
if (!entry.isDirectory()) {
foundFiles.add(entry.getName());
}
}
tarInput.close();
} catch (IOException ex) {
log.error(ex.getMessage());
}
return foundFiles;
}