Date/Time Missing in Zip files created by java.util.zip

Date/Time Missing in Zip files created by java.util.zip

Post by Lars-Inge » Tue, 13 Apr 2004 00:27:23


It looks like a bug. I can't get it to work. Here is what I did in C#.

using System;
namespace ConsoleZip
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
// Make a example file to zip.______________
java.io.FileWriter Onewrite = new java.io.FileWriter("One.txt");
Onewrite.write("Hello\r\n");
Onewrite.write("Yes, I'm a line too.\r\n");
Onewrite.write("Cool thing!\r\n");
Onewrite.close();
// _________________________________________



// Write the zip file with the file "One.txt" ____________
string filename = "output.zip";

java.util.zip.ZipOutputStream stream = new
java.util.zip.ZipOutputStream( new java.io.FileOutputStream(filename) );

java.io.FileInputStream inFile = new
java.io.FileInputStream("One.txt");
java.util.zip.ZipEntry entryOut = new
java.util.zip.ZipEntry("One.txt");
entryOut.setMethod( java.util.zip.ZipEntry.DEFLATED );

java.util.Date date = new java.util.Date();
entryOut.setTime( date.getTime() );

java.util.Date date3 = new java.util.Date( entryOut.getTime() );
System.Console.WriteLine( "[date in entry to be written]
"+date3.toGMTString() );

stream.putNextEntry( entryOut );

while ( inFile.available() != 0 )
stream.write( inFile.read() );

stream.closeEntry();
stream.close();
// ___________________________________________________



System.Console.WriteLine("__________________________________");
System.Console.WriteLine();



// Read the zip file 'output.zip' _____________________
java.util.zip.ZipFile zipFile = new java.util.zip.ZipFile(
"output.zip" );
java.util.Enumeration entries = zipFile.entries();
while ( entries.hasMoreElements() )
{
java.util.zip.ZipEntry entry =
(java.util.zip.ZipEntry)entries.nextElement();
System.Console.Write( "[In Zip file] "+entry.getName() );
java.util.Date date2 = new java.util.Date(
entry.getTime() );
System.Console.WriteLine( " - "+date2.toGMTString() );
}
zipFile.close();
// __________________________________________________
}
}
}



Lars-Inge Tnessen
www.larsinge.com
 
 
 

Date/Time Missing in Zip files created by java.util.zip

Post by mikegreonl » Fri, 16 Apr 2004 05:30:01

was able to reproduce the problem and I reported the bug to the dev team.

Thanks,

Michael Green
Microsoft Developer Support

--------------------
| Reply-To: "Lars-Inge Tnessen" <http://emailme.larsinge.com>
| From: "Lars-Inge Tnessen" <http://emailme.larsinge.com>
| References: < XXXX@XXXXX.COM >
| Subject: Re: Date/Time Missing in Zip files created by java.util.zip
| Date: Sun, 11 Apr 2004 17:27:23 +0200
| Lines: 80
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: < XXXX@XXXXX.COM >
| Newsgroups: microsoft.public.dotnet.vjsharp
| NNTP-Posting-Host: stud-035.vpn.uit.no 129.242.154.168
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.vjsharp:5816
| X-Tomcat-NG: microsoft.public.dotnet.vjsharp
|
| It looks like a bug. I can't get it to work. Here is what I did in C#.
|
| using System;
| namespace ConsoleZip
| {
| class Class1
| {
| [STAThread]
| static void Main(string[] args)
| {
| // Make a example file to zip.______________
| java.io.FileWriter Onewrite = new
java.io.FileWriter("One.txt");
| Onewrite.write("Hello\r\n");
| Onewrite.write("Yes, I'm a line too.\r\n");
| Onewrite.write("Cool thing!\r\n");
| Onewrite.close();
| // _________________________________________
|
|
|
| // Write the zip file with the file "One.txt" ____________
| string filename = "output.zip";
|
| java.util.zip.ZipOutputStream stream = new
| java.util.zip.ZipOutputStream( new java.io.FileOutputStream(filename) );
|
| java.io.FileInputStream inFile = new
| java.io.FileInputStream("One.txt");
| java.util.zip.ZipEntry entryOut = new
| java.util.zip.ZipEntry("One.txt");
| entryOut.setMethod( java.util.zip.ZipEntry.DEFLATED );
|
| java.util.Date date = new java.util.Date();
| entryOut.setTime( date.getTime() );
|
| java.util.Date date3 = new java.util.Date( entryOut.getTime()
);
| System.Console.WriteLine( "[date in entry to be written]
| "+date3.toGMTString() );
|
| stream.putNextEntry( entryOut );
|
| while ( inFile.available() != 0 )
| stream.write( inFile.read() );
|
| stream.closeEntry();
| stream.close();
| // ___________________________________________________
|
|
|
|
System.Console.WriteLine("__________________________________");
| System.Console.WriteLine();
|
|
|
| // Read the zip file 'output.zip' _____________________
| java.util.zip.ZipFile zipFile = new java.util.zip.ZipFile(
| "output.zip" );
| java.util.Enumeration entries = zipFile.entries();
| while ( entries.hasMoreElements() )
| {
| java.util.zip.ZipEntry entry =
| (java.util.zip.ZipEntry)entries.nextElement();
| System.Console.Write( "[In Zip file] "+entry.getName() );
| java.util.Date date2 = new java.util.Date(
| entry.getTime() );
| System.Console.WriteLine( " - "+date2.toGMTString() );
| }
|