Copier un repertoire à partir d'un archive

aaqil Messages postés 5 Date d'inscription mardi 18 mars 2003 Statut Membre Dernière intervention 15 avril 2003 - 15 avril 2003 à 14:13
CoreBreaker Messages postés 540 Date d'inscription dimanche 23 mars 2003 Statut Membre Dernière intervention 5 octobre 2007 - 16 avril 2003 à 21:23
j'ai un archive "archive.jar" qui contient un repertoire "rep" .
Dans un programme java, comment copier ce repertoire à partir de l'archive dans un emplacement "destination" donné ?

1 réponse

CoreBreaker Messages postés 540 Date d'inscription dimanche 23 mars 2003 Statut Membre Dernière intervention 5 octobre 2007 1
16 avril 2003 à 21:23
import java.io.*;
import java.util.*;
import java.util.jar.*;
import java.util.zip.*;

try
{
JarFile jar= new JarFile("archive.jar");
Enumeration enum= jar.entries();
byte [] buffer= new byte[1024];

new File("destination").mkdir();

while( enum.hasMoreElements() )
{
ZipEntry e= (ZipEntry)enum.nextElement();
String n= e.getName();
if( n.startsWith("rep") )
{
FileOutputStream o= new FileOutputStream(n);
InputStream i= jar.getInputStream(e);

CSFileUtils.transfer(i, o);
}
}
}
catch(Exception ex)
{
ex.printStackTrace();
}

/////////////////////////////////////////////////////////////////
// FICHIER: CSFileUtils.java

//import java.io.*;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

//import lata.*;
import lata.CSLataUtilsObject;

public class CSFileUtils
{
private final static int TRANFER_BUFFER_SIZE= 10240;

private static byte[] sTransferBuffer= new byte[TRANFER_BUFFER_SIZE];

public static void transfer(InputStream aInStream, OutputStream aOutStream)
throws IOException
{
int lLen;

while( (lLen= aInStream.read(sTransferBuffer, 0, TRANFER_BUFFER_SIZE)) > 0 )
aOutStream.write(sTransferBuffer, 0, lLen);
}
}

Core Breaker :)
0
Rejoignez-nous