将*.xml文件从zip复制到另一个目录,而无需使用java解压zip
何乐而不为 我有一堆*.zip文件,这些文件有很多*.log文件和其他东西,还有一个*.xml文件 我需要查找文件并将其复制到另一个目录 到目前为止,我在*.zip文件夹中找到了该文件 但现在我卡住了。 希望你们能帮忙。。。 谢谢 到目前为止,我掌握了以下代码:将*.xml文件从zip复制到另一个目录,而无需使用java解压zip,java,Java,何乐而不为 我有一堆*.zip文件,这些文件有很多*.log文件和其他东西,还有一个*.xml文件 我需要查找文件并将其复制到另一个目录 到目前为止,我在*.zip文件夹中找到了该文件 但现在我卡住了。 希望你们能帮忙。。。 谢谢 到目前为止,我掌握了以下代码: public static void main(String[] args) { String sPath = "c:/results/"; //String sFiles; F
public static void main(String[] args)
{
String sPath = "c:/results/";
//String sFiles;
File folder = new File(sPath);
File[] aListOfFiles = folder.listFiles();
try
{
//get all files in the folder
for (int i = 0; i < aListOfFiles.length; i++)
{
if (aListOfFiles[i].isFile())
{
//get path an file name
String sZipPath = aListOfFiles[i].getAbsolutePath();
//System.out.println("Absolute Path: " + sZipPath);
//open zip find the xml
ZipFile sourceZipFile = new ZipFile(sZipPath);
Enumeration e = sourceZipFile.entries();
while(e.hasMoreElements())
{
ZipEntry entry = (ZipEntry)e.nextElement();
String isXML = entry.getName();
if (isXML.endsWith(".xml"))
{
System.out.println(isXML);
//copieFile(File isXML,)
}
}
}
}
}
catch (IOException ioe)
{
System.out.println("Error while opening zip file " + ioe);
}
publicstaticvoidmain(字符串[]args)
{
String sPath=“c:/results/”;
//字符串文件;
文件夹=新文件(sPath);
文件[]aListOfFiles=folder.listFiles();
尝试
{
//获取文件夹中的所有文件
for(int i=0;i
不解压缩就无法复制。必须执行此操作,并且文件需要存储在内存中或保存到磁盘
难怪你被困在那里
要提取文件,请使用:
InputStream stream = sourceZipFile.getInputStream(entry);
然后,您可以通过自己编写整个复制逻辑或使用来将InputStream
复制到OutputStream
等FileOutputStream