私が使用している独自のプログラムは、解凍時にファイルの変更日を変更せずに、特定のファイルを圧縮して抽出します。また、プログラムのソース コードに基づいて独自の zip および抽出ツールを作成していますが、ファイルを解凍すると、すべての zip ファイルの変更日が解凍時刻と日付とともに表示されます。私の抽出のコードは次のとおりです。
public static int unzipFiles(File zipFile, File extractDir) throws Exception
{
int totalFileCount = 0;
String zipFilePath = zipFile.getPath();
System.out.println("Zip File Path: " + zipFilePath);
ZipFile zfile = new ZipFile(zipFile);
System.out.println("Size of ZipFile: "+zfile.size());
Enumeration<? extends ZipEntry> entries = zfile.entries();
while (entries.hasMoreElements())
{
ZipEntry entry = entries.nextElement();
System.out.println("ZipEntry File: " + entry.getName());
File file = new File(extractDir, entry.getName());
if (entry.isDirectory())
{
System.out.println("Creating Directory");
file.mkdirs();
}
else
{
file.getParentFile().mkdirs();
InputStream in = zfile.getInputStream(entry);
try
{
copy(in, file);
}
finally
{
in.close();
}
}
totalFileCount++;
}
return totalFileCount;
}
private static void copy(InputStream in, OutputStream out) throws IOException
{
byte[] buffer = new byte[1024];
System.out.println("InputStream/OutputStram copy");
while (true)
{
int readCount = in.read(buffer);
if (readCount < 0)
{
break;
}
out.write(buffer, 0, readCount);
}
}
入力ストリーム/出力ストリームのコピーを行う以外に、これを行うためのより良い方法があると確信しています。winRARで抽出しても、圧縮したファイルの日付は変更されないため、これが原因であると確信しています。