Alors voila j'ai creer un fichiers zip, pour pouvoir y stocker tout ce dont mon programme a besoin : ce zip contient des repertoires et des fichiers normaux.
J'ai commencé par creer ma fonction zip perso
mais celle-ci me renvoie une FileNotFoundException sur la ligne : FileOutputStream FileOutS = new FileOutputStream( ZipEnt.getName() );mais la fonction marche sur des zips sans repertoire
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39 public void Decompresser( String Archive, File FileDir ) throws Exception { final int m_BUFFER = 2048; byte Data[] = new byte[m_BUFFER]; // Fichier de destination BufferedOutputStream BuffOutS = null; int count = 0; try { // Ouverture du fichier à dézipper FileInputStream FileInS = new FileInputStream( Archive ); // Ouverture du buffer sur ce fichier BufferedInputStream BuffInS = new BufferedInputStream( FileInS ); // Ouverture du fichier zip à l'aide du buffer ZipInputStream ZipInS = new ZipInputStream( BuffInS ); ZipEntry ZipEnt; while ( ( ZipEnt = ZipInS.getNextEntry() ) != null ) { FileOutputStream FileOutS = new FileOutputStream( ZipEnt.getName() ); BuffOutS = new BufferedOutputStream( FileOutS, m_BUFFER ); while ( ( count = ZipInS.read( Data, 0, m_BUFFER ) ) != -1 ) { BuffOutS.write( Data, 0, count ); } BuffOutS.flush(); BuffOutS.close(); } ZipInS.close(); }
J'ai donc piquer une source du net pour pouvoir dézipper des archives contenant des repertoires :
et ca me donne la meme exception à la meme instructions :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84 public void UnZipPerso(String path) { try { final int BUFFER = 2048; // préparation du zip BufferedOutputStream dest = null; BufferedInputStream is = null; ZipEntry entry; ZipFile zipfile = new ZipFile(path); Enumeration e = zipfile.entries(); // recharche du nom du zip File pathNom = new File(path); String nomFichier = pathNom.getName(); String nom = nomFichier.substring(0, nomFichier.length() - 4); //System.out.println(nom); // création du dossier racine File NOM = new File(nom); NOM.mkdir(); // URL de base String URLbase = "." + "/" + nom ; // boucle d'extraction des fichiers while (e.hasMoreElements()) { // préparation du fichier courant à extraire entry = (ZipEntry) e.nextElement(); String url = entry.getName(); //System.out.println("Extracting: " + url); String URLfichier = URLbase + "/" + url; //System.out.println("URL: " + URLfichier); File URL = new File(URLfichier); if (isFile(URL.getName())) { // écriture du fichier (extraction) is = new BufferedInputStream (zipfile.getInputStream(entry)); int count; byte data[] = new byte[BUFFER]; FileOutputStream fos = new FileOutputStream(URLfichier); dest = new BufferedOutputStream(fos, BUFFER); while ( (count = is.read(data, 0, BUFFER)) != -1) { dest.write(data, 0, count); } dest.flush(); dest.close(); is.close(); } else { // zone répértoire URL.mkdirs(); } } } catch (Exception e) { e.printStackTrace(); } } private boolean isFile (String nom) { for (int i=nom.length()-1; i>=0; i--) { if (nom.charAt(i) == '.' ) { return true; } } return false; } }
Quelqu'un aurait -il une idée de la facon de procéder pour dézipper une archive contenant des repertoires ?java.io.FileNotFoundException: .\Fichiers\Framakey\FramaKiosk\bin\Profiles\default\g3flvb6k.slt\accel.cfg (Le chemin d'accès spécifié est introuvable)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileOutputStream.<init>(Unknown Source)
at CZip.UnZipPerso(CZip.java:215)
at CInterface$1.widgetSelected(CInterface.java:136)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:90)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:928)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3348)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2968)
at CInterface.main(CInterface.java:80)
Partager