Aide moi sur mon projet

Fermé
jayzman1 Messages postés 4 Date d'inscription mardi 15 décembre 2015 Statut Membre Dernière intervention 20 janvier 2016 - 16 déc. 2015 à 14:44
 jayzman1 - 4 janv. 2016 à 07:50
Bonjour,
voici mon projet
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
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";
        
    }

    
}

on peut faire dans un tableau mais ça ne marche pas encore,il ne trouve pas cygwin

le 2- jce dode marche bien

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) {
        }
         
    }
 
}


le 3- j'ai encore un code mais ça donne des erreurs et le cygwin,il ne trouve pas
voici mon code
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());
}

on peut faire dans un tableau mais ça ne marche pas encore,il ne trouve pas cygwin

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
 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); 
            } 

le fichier il y a des exceptions c'est pourquoi j'ai utilisé le regex ,
P.S: si possible,je veut que tout ça se lie et marche automatique!
merci a vous,
jayzman
A voir également:

1 réponse

fmvgld Messages postés 117 Date d'inscription dimanche 2 mars 2008 Statut Membre Dernière intervention 30 décembre 2015 9
30 déc. 2015 à 20:49
a tu des exception qui sont levé? si oui peut tu mettre les erreurs
0
bonjour et bonne année 2016
Pour le 1 il n'y a pas d'erreur juste qu'il return le fichier vide,
Pour le 2 il marche bien
Pour le 3 il a déjà trouvé le cygwin mais il ne compile pas cmd[1] et cmd[2]
pour le 4 le plus important maintenant,je ne sais pas l'enregistrer dans la base de données
je un fichier text qui ressemble a ceci

table
num : 001
nom : JAYZ
prenom : Man

table1
num : 002
nom : JAYZ1
prenom : Man1

comment je dois faire pour l'enregistrer dans la base de données

merci
jayzman1
0