bonjour,
je suis nouveau ici mais j'ai très besoin d'aide,
voici ce que je dois faire:
1- télécharger dossier sur un serveur FTP et placer dans un dir local(code java)
2-de-zipper les éléments dans le dossier un par un et placer le nom des éléments dans un fichier.text successivement séparer par un espace (code java)
3-exécuter le fichier dans cygwin automatiquement et envoyer dans un fichier1.txt (code java)
4-lire le fichier1.txt et ajouter dans une base de donnée MySQL (code java)
merci à vous
le 1- j'ai déjà un code mais ça ne marche pas il a retourné les fichiers vide
voici mon code
le 2- ce code marche bien
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 import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.text.DateFormat; import static javaapplication5.MonFTP.receptionner; import org.apache.commons.net.ftp.FTP; import org.apache.commons.net.ftp.FTPClient; import org.apache.commons.net.ftp.FTPFile; import org.apache.commons.net.ftp.FTPReply; public class MonFTP { public static FTPClient ftp; private static BufferedOutputStream out; public static void main(String[] args) { String result; result = receptionner("C:\\cygwin\\home\\colombna\\decoder\\traces",""); System.out.println("Result: " + result); } public static String receptionner(String chemin, String nomFichier) { try { String server = "xxx"; String username = "xxx"; String password = "xxx"; // Connect and logon to FTP Server FTPClient ftp = new FTPClient(); ftp.connect(server); ftp.login(username, password); System.out.println("Connected to " + server + "."); System.out.print(ftp.getReplyString()); // List the files in the directory ftp.changeWorkingDirectory("/dir"); FTPFile[] files = ftp.listFiles(); System.out.println("Number of files in dir: " + files.length); DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT); for (int i = 0; i < files.length; i++) { System.out.print(df.format(files[i].getTimestamp().getTime())); System.out.println("\t" + files[i].getName()); String filename = files[i].getName(); File f1 = new File(chemin+"/"+filename+""); out = new BufferedOutputStream(new FileOutputStream(f1),8); nomFichier = files[i].getName(); } ftp.retrieveFile(nomFichier+"", out); ftp.logout(); ftp.disconnect(); } catch (Exception e) { e.printStackTrace(); } return "reussi"; } }
le 3- j'ai encore un code mais ça donne des erreurs et le cygwin,il ne trouve pas
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 import java.io.BufferedReader; import static java.io.FileDescriptor.in; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.Arrays; import java.util.zip.GZIPInputStream; import java.util.zip.GZIPOutputStream; public class GZIPExample { public static void main(String[] args) throws IOException { // String file = "C:\\cygwin\\home\\colombna\\decoder\\tesbuffer.log"; String gzipFile = "D:\\Asa_zo\\macrogpeh\\GPEH_CALL_FAIL\\A20150715.1115+0300-1130+0300_SubNetwork=ANRNC02,MeContext=ANRNC02_rnc_gpehfile_Mp0.bin.gz"; String newFile = "C:\\cygwin\\home\\colombna\\decoder\\C.bin"; // compressGzipFile(file, gzipFile); InputStream in; decompressGzipFile(gzipFile, newFile); } private static void decompressGzipFile(String gzipFile, String newFile) { try { FileInputStream fis = new FileInputStream(gzipFile); try (GZIPInputStream gis = new GZIPInputStream(fis); FileOutputStream fos = new FileOutputStream(newFile)) { byte[] buffer = new byte[1024]; int len; while((len = gis.read(buffer)) != -1){ fos.write(buffer, 0, len); } } } catch (IOException e) { } } private static void compressGzipFile(String file, String gzipFile) { try { try (FileInputStream fis = new FileInputStream(file); FileOutputStream fos = new FileOutputStream(gzipFile); GZIPOutputStream gzipOS = new GZIPOutputStream(fos)) { byte[] buffer = new byte[1024]; int len; while((len=fis.read(buffer)) != -1){ gzipOS.write(buffer, 0, len); } } } catch (IOException e) { } } }
voici mon code
on peut faire dans un tableau mais ça ne marche pas encore,il ne trouve pas cygwin
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 try { Process p = Runtime.getRuntime().exec("C:/cygwin/bin/bash -c C:\\cygwin\\home\\colombna\\decoder\\TEST.sh"); InputStream outStream = p.getInputStream(); // normal output of the shell InputStream errStream = p.getInputStream(); // error output of the shell // TODO: start separate threads to read these streams PrintStream ps = new PrintStream(p.getOutputStream()); ps.println("cd decoder"); ps.println("bash TEST.sh"); ps.println("exit"); ps.close(); p.waitFor(); if(p.exitValue() == 0) { JOptionPane.showMessageDialog(this,"execution reussi!"); } else { JOptionPane.showMessageDialog(this,"execution non reussi!"); } } catch(Exception e) { System.out.println("Exception: "+ e.toString()); }
pour le 4 j'ai deja un code mais juste lire le fichier mais je ne sais pas l'enregistrer dans une base
voici mon code
le fichier il y a des exceptions c'est pourquoi j'ai utilisé le regex ,
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 JFileChooser dialogue = new JFileChooser(); // affichage dialogue.showOpenDialog(null); String filePath = ""+ dialogue.getSelectedFile() ; try{ BufferedReader buff = new BufferedReader(new FileReader(filePath)); try { String line; // Lire le fichier ligne par ligne // La boucle se termine quand la méthode affiche "null" Pattern pattern = Pattern.compile("\\[(.*)\\]\\s+\\/(\\d+)\\s+\\((.*)\\)\\s+([^\\s]+)\\s+\\((.*)\\)\\s+\\((.*)\\)\\s+\\((.*)\\)\\s+\\((.*)\\)\\s+\\((.*)\\)\\s+\\((.*)\\)\\s+\\((.*)\\)\\s+\\((.*)\\)\\s+\\((.*)\\)"); while ((line = buff.readLine()) != null) { Matcher matcher = pattern.matcher(line); if (matcher.find()) { for (int i = 1; i <= matcher.groupCount(); i++) { this.textArea1.setText(matcher.group(i)); System.out.println(matcher.group(i) ); } } } buff.close(); //Lecture fini donc on ferme le flux } catch (IOException e){ System.out.println(e.getMessage()); System.exit(1); } } catch (IOException e) { System.out.println(e.getMessage()); System.exit(1); }
P.S: si possible,je veut que tout ça se lie et marche automatique!
merci a vous,
jayzman
Partager