Extracting .tar files

I have the com.ice.tar package from http://www.trustice.com/java/tar/ and I have the code shown below compiling just fine. However, I need to extract .tar files and this code will only extract tar.gz files. Does anyone know what I need to change to my code to get it to extract .tar files? Thanks,
import com.ice.tar.*;
import javax.activation.*;
import java.io.*;
import java.util.zip.GZIPInputStream;
public class untarFiles
public static void main(String args[]) {
try {
untar("c:/Files/AnyFile.tar.gz",new File("c:/Files/"));
catch(Exception e) {
e.printStackTrace();
System.out.println(e.getMessage());
private static void untar(String tarFileName, File dest) throws IOException {
//assuming the file you pass in is not a dir
dest.mkdir();
//create tar input stream from a .tar.gz file
TarInputStream tin = new TarInputStream( new GZIPInputStream
( new FileInputStream(new File(tarFileName))));
//get the first entry in the archive
TarEntry tarEntry = tin.getNextEntry();
while (tarEntry != null){//create a file with the same name as the tarEntry
File destPath = new File(dest.toString() + File.separatorChar + tarEntry.getName());
if(tarEntry.isDirectory()){
destPath.mkdir();
} else {
FileOutputStream fout = new FileOutputStream(destPath);
tin.copyEntryContents(fout);
fout.close();
tarEntry = tin.getNextEntry();
tin.close();
}

hey ppl, i have the same assignment of extracting tar.Z files using java.
I have the same trustice.com library com.ice.tar
I've used basically the same code given in the previous post.
It is givin me the followin exception when i try using tar.Z files :
com.ice.tar.InvalidHeaderException: bad header in block 0 record 0, header magic is not 'ustar' or unix-style zeros, it is '-50112-51-424592-71', or (dec) -50, 112, -51, -42, 45, 92, -71
     at com.ice.tar.TarInputStream.getNextEntry(Unknown Source)
     at filterdialog.readTar(filterdialog.java:101)
     at filterdialog$1.actionPerformed(filterdialog.java:80)
     at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
     at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
     at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
     at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
     at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
     at java.awt.Component.processMouseEvent(Unknown Source)
     at javax.swing.JComponent.processMouseEvent(Unknown Source)
     at java.awt.Component.processEvent(Unknown Source)
     at java.awt.Container.processEvent(Unknown Source)
     at java.awt.Component.dispatchEventImpl(Unknown Source)
     at java.awt.Container.dispatchEventImpl(Unknown Source)
     at java.awt.Component.dispatchEvent(Unknown Source)
     at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
     at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
     at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
     at java.awt.Container.dispatchEventImpl(Unknown Source)
     at java.awt.Window.dispatchEventImpl(Unknown Source)
     at java.awt.Component.dispatchEvent(Unknown Source)
     at java.awt.EventQueue.dispatchEvent(Unknown Source)
     at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
     at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
     at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
     at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
     at java.awt.EventDispatchThread.run(Unknown Source)

Similar Messages

  • Easy Question:  Correct tar command to extract tar file

    If I have a tar file I wish to extract and let it automatically place the files where the belong what should I type in the Terminal, assuming I'm in the directory the tar file resides?

    tar xvf [tar filename]
    If the tar file was created with GNU tar, then it may be malformed (using a non-standard extension for long paths). In this case you will need to use gtar (/usr/sfw/bin/gtar).
    Paul

  • Tar extract file in particular directory excluding path stored in tar file

    In winzip you have chk box 'Use Foldername', if you uncheck it, all files will be extracted to path given in Extract to:
    Like winzip, do you have facility to extract files from tar file to a particular directory ignoring path stored in tar file.
    os - linux,unix
    regds

    Using -C <new_directory> options creates
    subdirectories under the new_directory as per path
    stored in tar file
    I just want to extract the files in the -C directory.
    e.g.
    # tar -tvf archive.tar
    -rw-r----- oracle/oinstall 4669440 2006-11-30
    13:23:02 /app/fmb/FORM1.fmb
    -rw-r----- oracle/oinstall 200704 2006-11-29
    10:18:25 /app/fmb/FORM2.fmb
    when i give following command
    tar -xvf archive.tar -C TargetDir
    creats subdirectory app/fmb in this TargetDir and
    then extract the files Forms1.fmb
    TargetDir/app/fmb/FORM1.fmb
    TargetDir/app/fmb/FORM2.fmb.
    where as i want FORM1.fmb and FORM2.fmb in TargetDir
    TargetDir/FORM1.fmb
    TargetDir/FORM2.fmb
    regdsit's include directory information when you run tar cvf.
    you can do the following action
    1. cd /app/fmb/
    2. tar cvf archive.tar *
    3. tar -xvf archive.tar -C TargetDir

  • Extract tar.gz file

    Hi,
    I have a file with extension tar.gz and i need to extract it. I tried with GZIPInputStream class of java.util.zip package but could not do it. Below is the code snippet for the same. Please suggest the way we can handle this problem in Java.
    String filename = "C:\\TarFile\\Test.20110519_123033_00001.tar.gz";
                   final int BUFFER_SIZE = 2048;
                   try {
                        BufferedOutputStream dest = null;
                        FileInputStream fis = new FileInputStream(filename);
                        GZIPInputStream zis = new GZIPInputStream(new BufferedInputStream(fis));
                        int len;
                        FileOutputStream fos = new FileOutputStream("C:\\TarFile\\Test.20110519_123033_00001.tar");
                        dest = new BufferedOutputStream(fos, BUFFER_SIZE);
                        byte data[] = new byte[BUFFER_SIZE];
                        while ((len = zis.read()) != -1) {
                             //int count;
              // write the files to the disk
              dest.write(data, 0, len );
         //dest.flush();
         dest.close();
              zis.close();
    }catch(Exception e) {
    Thanks.

    By words "could not do it" , it should be very much clear that - i could not extract the file tar.gz completely. That is what the actual problem is. I understand people should have commonsense to understand it.
    Of course we understand it. What we don't understand is what happened instead. Exception? Data corruption? Nothing? Computer exploded?
    You aren't going to get anywhere here or indeed in life by making rude remarks about common sense to people who are trying to help you. You provided one binary digit of information. You needed to provide more. Would you accept that as a bug report from a user? or would you ask for some details?

  • Extracting tar.bz2 files.

    How can i extract tar.bz2 files?. zip, jar, tar can be extracted within java. But how tar.bz2?.

    Some tars have built-in knowledge of the bz2 (bunzip) compression format.
    Tar ("tape archive") is to package several files in one archive or to extract them. The archive files can be called "*.tar".

  • Extracting file from a TAR file with java.util.zip.* classes

    Is there a way to extract files from a .TAR file using the java.util.zip.* classes?
    I tried in some ways but I get the following error:
    java.util.zip.ZipException: error in opening zip file
    at java.util.zip.ZipFile.<init>(ZipFile.java127)
    at java.util.zip.ZipFile.<init>(ZipFile.java92)
    Thank you
    Giuseppe

    download the tar.jar from the above link and use the sample program below
    import com.ice.tar.*;
    import java.util.zip.GZIPInputStream;
    import java.io.*;
    public class untarFiles
         public static void main(String args[]){
              try{
              untar("c:/split/20040826172459.tar.gz",new File("c:/split/"));
              }catch(Exception e){
                   e.printStackTrace();
                   System.out.println(e.getMessage());
         private static void untar(String tarFileName, File dest)throws IOException{
              //assuming the file you pass in is not a dir
              dest.mkdir();     
              //create tar input stream from a .tar.gz file
              TarInputStream tin = new TarInputStream( new GZIPInputStream( new FileInputStream(new File(tarFileName))));
              //get the first entry in the archive
              TarEntry tarEntry = tin.getNextEntry();
              while (tarEntry != null){//create a file with the same name as the tarEntry  
                   File destPath = new File(
                   dest.toString() + File.separatorChar + tarEntry.getName());
                   if(tarEntry.isDirectory()){   
                        destPath.mkdir();
                   }else {          
                        FileOutputStream fout = new FileOutputStream(destPath);
                        tin.copyEntryContents(fout);
                        fout.close();
                   tarEntry = tin.getNextEntry();
              tin.close();
    }

  • Uncompress and extract tar.Z file issue

    Does anybody could help me on how to properly and untar files in with tar.Z extension.
    Looks like files where tar with gtar utility and compressed on top of it. (O/S AIX)
    I used following method to uncompress and extract actual file and some files worked but large files (> 10 G) give me trouble
    Here is my example:
    uncompress data1.dbf.tar.Z
    ##This creates data1.dbf tar file
    tar -xvf data1.dbf.tar
    This gives me following message
    x data1.dbf, -2594003015419476674 bytes, -5066412139491164 tape blocks
    and creates 0 byte data1.dbf file

    One would assume
    firstly: this is not an Oracle problem
    secondly: gtar has a -x switch, and man gtar would tell you all about it
    thirdly: maybe the filesystem you are untarring to doesn't allow files greater than 2G.
    Who can tell?
    Sybrand Bakker
    Senior Oracle DBA

  • Extract *.tar.gz file, error tar: 0511-164 There is a media read or write b

    when try to:
    $gzip -dc /dbdump/patch/oraInventory_BK.tar.gz | tar xf /tmp/t
    tar: 0511-164 There is a media read or write block size error.
    how to unzip/ extract tar sucussfully?
    AIX box
    thanks

    Preferably Unix questions are answered by consulting man pages or an Unix forum.
    Your questions is 100 percent of topic here. Kindly stop posting Unix questions here.
    Sybrand Bakker
    Senior Oracle DBA

  • Error ,opening a  tar file created by TarOutputStream

    Iam trying to create a tar file using TarOutputStream with the code below :
    try {
    TarOutputStream tout = new TarOutputStream(out);
    for (int i = 0; i < files.length; i++) {
    if (files.getPath() == null) {
    continue;
    File f = new File(wsdir, files[i].getPath());
    if (!f.exists()) {
    continue;
    TarEntry te = new TarEntry(files[i].getPath());
    size += f.length();
    te.setSize(size);
    tout.putNextEntry(te);
    try {
         FileInputStream in = null;
         try {
              in = new FileInputStream(f);
              byte buf[] = new byte[1024];
              int n;
              while ((n = in.read(buf)) > 0) {
              tout.write(buf, 0, n);
         } finally {
              if (in != null) {
              in.close();
         } catch (IOException e) {
         e.printStackTrace();
    tout.close();
    } catch (IOException e) {
    e.printStackTrace();
    return false;
    The above code succcessfully creates the tar file but while opening the tar file Iam getting the error - Error reading header after processing 1 enries

    I created a zip file by providing the relative paths
    of the files using the java.util.zip package.I
    downloaded it through a web application.It was
    downloaded successfully and the zip file is showing
    100 kb.When i tried opening zip file from windowsXP
    SP2 and i am not able to view or extract the
    contents.It says 'Windows has blocked access to these
    files to help protect your computer'. Go and complain to Microsoft. It's a Windows XP SP2 security feature. Read the manual or help about how to deal with it. It's not a Java problem.

  • Batch file extracting all files from nested archives

    I have managed to leverage a powerful
    forfiles command line utility with the mighty
    7z compression program.
    Below is a simple batch file extracting all files from nested archives hidden at any depth inside other archives and/or folders. After the extraction each archive file turns into a folder having the archive file name. If, for example, there was an "outer.rar"
    archive file containing nothing but an "inner.zip" archive with only "afile.txt" inside, "outer.rar" becomes "...\outer.rar\inner.zip\afile.txt" file system path.
    @echo off
    rem extract_nested_archives.bat
    move %1 "%TMP%"\%2
    md %2
    7z x -o%1 -y %TMP%\%2
    del "%TMP%"\%2
    for %%a in (zip rar jar z bz2 gz gzip tgz tar lha iso wim cab rpm deb) do forfiles /P %1 /S /M *.%%a /C "cmd /c if @isdir==FALSE extract_nested_archives.bat @path @file"
    ARCHIVES ARE DELETED DURING THE EXTRACTION! Make a copy before running the script!
    "7z.exe" and "extract_nested_archives.bat" should be in folders available via the %PATH% environment variable.
    The first parameter of extract_nested_archives.bat is the full path name of the archive or folder that should be fully expanded; the second parameter is just the archive or folder name without the path. So you should run "c:\temp\extract_nested_archives.bat
    c:\temp\outer.rar outer.rar" from the command line to completely expand "outer.rar". "c:\temp" must be the current folder.
    Best regards, 0x000000AF

    Incredibly useful!  Thank you so much.  I did make a couple of small changes to make the script a little easier to use from the end-user perspective.
    First - I don't like making the user input the redundant second parameter, so I added this snippet which extracts it from the first parameter.  The first line of the snippet enables delayed expansion so that special characters in our file name don't
    break anything.  The second line pulls the parameter into a variable, and the 3rd line uses delayed expansion on that new variable.  Before implementing delayed expansion I had problems with file paths which included parentheses.
    SetLocal EnableDelayedExpansion
    Set SOURCE=%1
    For %%Z in (!source!) do (
    set FILENAME=%%~nxZ
    set FILENAME=%FILENAME:"=%
    Anyway once that was done, I just used %FILENAME% everywhere in the script instead of
    %2 (making sure to correct quotes as needed)
    This way, to run my script all you need to run is:
    C:\temp\extract_nested_archives.bat C:\temp\Archive.zip
    Second - I didn't want to modify the Windows environment variable.  So I replaced
    7z with "%PROGRAMFILES%\7-zip\7z.exe"
    I also replaced extract_nested_archives.bat with "%~f0" (which represents the full path+filename of the current script).
    Here is my full script now.  Tested on Windows 8 with the 64-bit version of 7-zip installed:
    @echo off
    Setlocal EnableDelayedExpansion
    Set source=%1
    For %%Z in (!source!) do (
    set FILENAME=%%~nxZ
    set FILENAME=%FILENAME:"=%
    move /Y %1 "%TMP%\%FILENAME%"
    md "%FILENAME%"
    "%PROGRAMFILES%\7-zip\7z.exe" x -o%1 -y "%TMP%\%FILENAME%"
    DEL "%TMP%\%FILENAME%"
    for %%a in (zip rar jar z bz2 gz gzip tgz tar lha iso wim cab rpm deb) do (
    forfiles /P %1 /S /M *.%%a /C "cmd /c if @isdir==FALSE "%~f0" @path @file"

  • Best practice: tar file handling through java on Linux

    What would be the better way to handle large size tar files (size may be more 1 GB) on Linux using Java? One way would be by using linux "tar" command through Runtime.exec, another option is through Java zip classes?
    Btw, functionality I am doing is extract the large tar file, remove some files and tar it back to make a smaller size tar ball. I am not too sure if Java provides an api to remove individual files/directory from a zip file.

    A tar file is not a zip file.
    Java provides no classes that handle .tar files by default.
    It does provide classes to handle the gzip compression that's often applied to .tar files (resulting in .tar.gz or .tgz files).
    So you either search for a library that handles tar files in Java or invoke tar as an external process.

  • Extraction tar.gz archives without leaving a .tar archive behind

    Hello!
    When I double-click on a .tar-gz-archive in the Finder, It extracts two things: a tar-archive and the actual content of the file. In 99% of the cases I don't want an additional tar file eating my disk space - is there any way to tell "BomArchiveHelper" (the Program that extracts archives) not to store tar archives?

    Good to know... is there a Linux native format for backups that does incorporate fault tolerance much like the rar format allows for parity or recovery records?

  • Problems extracting tar.gz and zip

    Hi ^^
    So, I'm running Arch and Openbox and I was going to install GTK2 themes when I noticed my tar.gz file wouldn't open - then I remembered I hadn't installed p7zip and so I did - still no luck... I even rebooted the computer, but still no luck...
    Then I thought, maybe I needed to determine which application would unzip files and I tried to use mime to do it for me.. So I typed in the terminal
    mimeopen -d ~/Downloads/Dust-0.4.tar.gz
    and this is what was returned:
    No applications found for mimetype: application/x-compressed-tar
    I've also tried with zip files I had lying around but the same thing happens, except the error is:
    No applications found for mimetype: application/zip
    ... I don't know what else to do, I've had Openbox and Arch for a few months now and I never had this problem.. And then my HDD died, I reinstalled Arch and OB and this is happening... I probably forgot something, but if you could help..
    ^^ thanks in advance

    Thanks for the article, I also tried their method with xdg-mime however it didn't work either...
    See, first I typed this in the terminal:
    xdg-mime query filetype ~/Downloads/Dust-0.4.tar.gz
    so I'd know the filetype... and it returned:
    application/x-gzip; charset=binary
    .. So far so good, right..?
    Then I tried to make p7zip the default app for this...
    xdg-mime default p7zip application/x-gzip
    Apparently I needed to ask .desktop after the app, so I did
    xdg-mime default p7zip.desktop application/x-gzip
    and... this is what I've got now:
    /usr/bin/xdg-mime: line 664: /home/vandakiara/.local/share/applications/defaults.list.new: No such file or directory
    grep: /home/vandakiara/.local/share/applications/defaults.list.new: No such file or directory
    /usr/bin/xdg-mime: line 666: /home/vandakiara/.local/share/applications/defaults.list.new: No such file or directory
    /usr/bin/xdg-mime: line 668: /home/vandakiara/.local/share/applications/defaults.list.new: No such file or directory
    mv: impossível analisar «/home/vandakiara/.local/share/applications/defaults.list.new»: No such file or directory
    ..... any ideas? Btw, my problem isn't really working with mime - I've set default apps for stuff a bunch of times... My real problem is being unable to extract compressed files, that's all...

  • Error extracting webauth file

    Hi there - I'm having a problem downloading a simple webauth file to my 2106C. I turned debug on and this is what it show:
    TFTP receive complete... extracting webauth files.
    Thu Feb 21 07:52:51 2008: Still waiting! Status = 2
    Thu Feb 21 07:52:54 2008: upd_extract_webauth_components
    Thu Feb 21 07:52:54 2008: tar_file_name = /mnt/application/webauth.tar
    Thu Feb 21 07:52:54 2008: prsnt_strg = tar -C /mnt/application/webauth_ramdisk/ -xf /mnt/application/webauth.tar
    Thu Feb 21 07:52:54 2008: login.html not found in the webauth bundle downloaded
    Thu Feb 21 07:52:54 2008: RESULT_STRING: Error extracting webauth files.
    Thu Feb 21 07:52:54 2008: RESULT_CODE:18
    I noticed it says that there is no login.html fiel, but that;s not true. I do have one login.html file. I have tried everything and I am using PicoZip (30 day free version) to tar the file. I was able to do it once, but then I needed to modify the page and since then I have not been successfull. Any help would be greatly appreciate it.
    Cheers!

    All - problem ahs been solved. This is how I did it jsut in case someone else runs into the same issue. I noticed that the login.html file had a firefox icon (firefox was my defualt browser) I uninstalled firefox and archive the fiel again and boom -success . Weird, right? well I don't know if that was the issue, but it got resolved so you you run into the same issue, maybe is worth a try.
    CheerS!

  • WLC 5508 - Error extracting webauth files.

    Hi all,
    i am getting an error during the Upload of Login page for WLC 5508 customized.
    After the upload is completed i receveid the error "Error extracting webauth files."
    I tried to create the file *.tar with different program (winrar, 7zip, gnu tar, etc)
    anyone know the solution for this problem?
    Thanks
    Marco

    TQVVM Marco, it helps and issue resolved. I was downloading a folder consists of (login.html+folder CSS) compressed .TAR but failed. Instead of putting in a folder and directly downloaded the compressed .TAR and it was extracted successfully.
    Thanks.

Maybe you are looking for

  • Mp3 loops no longer working after upgrade.

    Heyho, I am a podcaster, and my strategy had been to copy a default GarageBand project that already had some segments I cut from an mp3 song in a separate track for the intro and outro. After upgrading to GB3, these mp3 segments no longer play (while

  • How to determine the object in the tablespace

    Hi I have a problem with my database, How can i determine the object in the tablespace and how do move old tablespace into new tablespace and how to drop existing tablespace. Thanks

  • Implementing File Upload component + Java Mail

    Guys, Brief Intro : I have a form with some input fields. Upon submission of the form all the necessary information is submitted ro R/3 system and a mail is send to lets say administrators. I have Java Mail program for sending emails. My requirement

  • Bapi to change "assignment" field on acct doc

    Hi, After the check run creates accounting docs, we want to update the "assignment" field on the accounting document (BSEG-ZUONR) with the check number.  Is there a BAPI I can use?  Or is this a job for a call transaction program? Thanks, Dennis

  • Email Message Indicator.. no message!

    I am new to this 8900 Curve.. I have spent ages trying to sort out my first problem, so any help would be appreciated. I have an email message icon (not sms as it isn't slanted), but I have no unread messages anywhere. I have managed to find the vari