right? From the message, it looks like the tar tool expects you to specify the size of an entry before you write to it. I see that TarEntry has a setSize() method. I imagine you should try inserting a line like
Depending on what other messages you get, you may have to set other fields in the TarEntry before you write the contents.
I note that TarEntry has other constructors, and one of these takes a File as an argument. And the documentation says that it constructs the header for you based on the information in the file. To me, this sounds like less work for the programmer. Less work is good.
I also see that you're doing this:
You might want to check out the method listFiles() (in the File class). My experience is that if the thing you're talking about is a file, then a File object is much more useful that a String representing a file name. If you use a File rather than a String, you usually end up doing less work. Again, less work is good.
After some changes from what you have said, i got the following error : com.ice.tar.InvalidHeaderException : file name is greater than 100 characters, c:\csharpzip\SharpZipLibSample\samples\DIME\DimeDataSetServiceConsumer\DimeDataSetServiceConsumer.csproj
If i use apache ant package, the same error occured too : Exception in thread "main" java.lang.RuntimeException : file name 'c:\csharpzip\SharpZipLibSample\samples\DIME\DimeDataSetServiceConsumer\DimeDataSetServiceConsumer.csproj' is too long <> 100 bytes)
Can someone give me a hint, how to overcome the problem, thanks very much
Note : now i use listFiles what you suggested(and recommended), is this implementation true, i mean the code.
Some versions of tar do not support names (paths, really) longer than 100 chars. If you've got paths longer than that, you won't be able to use a version that doesn't allow lengths > 100 chars. Fortunately there seem to be other choices. I don't see a way to use com.ice.tar for this. But it looks like org.apache.tools.tar will work. Try this:
Note also that you may want to put in some logic to modify the names a bit when you create entries. If you're tarring up everything from c:\csharpzip (as the base directory) you probably don't want to include the c:\csharpzip in the name. Because when someone untars the files, they will probably be on another machine with a different root directory. Insead you want a relative path name. Which means replacing
first thanks sheriff(Jim), you guide me in right paths, how can i modify the code using relative path ? (below is the modified code with relative path but still error when i untar it, all will be extracted in one directory, can you correct my fault ?) 2. Is it better to use rekursive method if i want to backup more than 100 GB(until 500 GB) for my backup programm, i am afraid that they eat much ram and cause memory defect. Or it is better to use iterative one, but more slower. 3. Is it better to save all the paths recusively in Java Collection, example List, ArrayList, Vector. But i dont know which is better, if the paths more than 1.000.000.000 which one is better ? after it, retrieve all the paths from the Collection and throw it to FileInputStream and TarEntry.
Hello expert people, i want to retrieve the long name of entry, how can i use the method from TarEntry : isGNULongNameEntry(). If i try "if(tarentryobject.isGNULongNameEntry())" then a error will be thrown, "invalid method declaration; return type required", ';' expected isGNULongNameEntry(). Any Help will be appreciated.
Hallo expert people, i think, there is a bug in package org.apache.tools.tar, if i try to tar a path longer than 100 chars, it will be success with method tos.setLongFileMode(TarOutputStream.LONGFILE_GNU); , but i try to untar it again there is a following error :
java.io.FileNotFoundException: c:\tar2\BEST BYTE AP_NET Mania_ @8<5@ :>40 !60BL ViewState.htm at java.io.FileOutputStream.open<Native Method> at java.io.FileOutputStream.<init><FileOutputStream.java:179> at java.io.FileOutputStream.<init><FileOutputStream.java:131> at UntarBest.untar<UntarBest.java:48> at UntarBest.main<UntarBest.java:11>
and i try in csharp, there is error too : System.ArgumentException : IILEGAL characters in path.
I think, i should use method isGNULongNameEntry() from TarEntry, but i dont know how use it rightly. Here is my untar code. Any Help will be appreciated.