Partage
  • Partager sur Facebook
  • Partager sur Twitter

Copier deux fichier dans deux dossier différents

Sujet résolu
    5 mai 2010 à 10:52:49

    Bonjours a tous :)
    Je vous pris de m'excuser car le titre de mon post ne semble pas très explicite mais je ne s'avais pas comment le formuler autrement.

    Mon soucie étant que j'ai repris le travail d'un ancien stagière qui permetter de crypter une clée USB, et durant l'installation il y a 2 fichier (const.ini et licence.ini) qui se colle dans la racine de ma clée USB, mais je voudrais que ses fichiers se colle dans deux dossier en racine de ma clée USB, un dossier "English" et l'autre "Francais".
    Voici le code :

    package usbnumecrypt;
    
    import java.awt.Cursor;
    import java.io.BufferedReader;
    import java.io.FileNotFoundException;
    import java.io.UnsupportedEncodingException;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.nio.channels.FileChannel;
    import java.util.ArrayList;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    
    import java.io.IOException;
    import java.io.InputStreamReader;
    import javax.crypto.spec.SecretKeySpec;
    import javax.swing.JFileChooser;
    import usbnumecrypt.USB.*;
    
    /**
     *
     * @author  pippin
     */
    public class Crypter extends javax.swing.JFrame {
    
        private ArrayList<USBKey> cles;
        private ArrayList<File> keyRoot;
        private File directory,tempDir;
        private int vendorID, productID;
        private SecretKeySpec key1;
        private DesEncrypter cipher;
        private boolean creating;
        
        /** Creates new form Crypter */
        public Crypter(int vendorID,int productID, File directory) {
            creating=true;
            this.setCursor(Cursor.WAIT_CURSOR);
            
            
            this.vendorID = vendorID;this.directory=directory;
            this.productID = productID;
            File reg;
            FileOutputStream stream=null;
            try {
                
                String k1="4??%????";
                
                key1= new SecretKeySpec(k1.getBytes("UTF8"),"DES");
                
                cipher= new DesEncrypter(key1);
                
                
           
                actualiser();
                initComponents();
                java.awt.Dimension screenSize = java.awt.Toolkit. getDefaultToolkit (). getScreenSize ();
                this.setBounds(screenSize.width/2, screenSize.height/2-this.getHeight()/2, this.getWidth(), this.getHeight());
            
                jDialog1.setBounds(screenSize.width/2-this.getWidth(), screenSize.height/2-this.getHeight()/2, jDialog1.getWidth(), jDialog1.getHeight());
                validRootList.setListData(keyRoot.toArray());
                
                
                String str1 ="";
                for (int i = 0; i != key1.getEncoded().length; i++) {
                    str1+=(int)key1.getEncoded()[i];
                }
                
                jTextArea1.setText( " cliquer sur \"Crypter\" pour lancer le processus\n\n " +
                        "masque VendorID=0x"+Integer.toHexString(vendorID)+"" +
                        "\n masque productID=0x"+Integer.toHexString(productID)+
                        "\n DES key : "+str1+
                        "\n\n les fichiers d'installation se trouvent dans : \n "+directory.toString());
                
                
            } catch (UnsupportedEncodingException ex) {
                Logger.getLogger(Crypter.class.getName()).log(Level.SEVERE, null, ex);
            } finally {
                try {
                    if(stream!=null)
                        stream.close();
                } catch (IOException ex) {
                    Logger.getLogger(Crypter.class.getName()).log(Level.SEVERE, null, ex);
                }finally{
                    this.setCursor(Cursor.DEFAULT_CURSOR);
                }
            }
           
        }
    
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
         */
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
        private void initComponents() {
    
            fileChooser = new javax.swing.JFileChooser();
            jDialog1 = new javax.swing.JDialog();
            fileField = new javax.swing.JTextField();
            jLabel1 = new javax.swing.JLabel();
            parcourir = new javax.swing.JButton();
            vidField = new javax.swing.JTextField();
            jLabel2 = new javax.swing.JLabel();
            pidField = new javax.swing.JTextField();
            jLabel3 = new javax.swing.JLabel();
            valider = new javax.swing.JButton();
            cancel = new javax.swing.JButton();
            jScrollPane1 = new javax.swing.JScrollPane();
            validRootList = new javax.swing.JList();
            crypter = new javax.swing.JButton();
            quitter = new javax.swing.JButton();
            jScrollPane2 = new javax.swing.JScrollPane();
            jTextArea1 = new javax.swing.JTextArea();
            refresh = new javax.swing.JButton();
            modif = new javax.swing.JButton();
    
            fileChooser.setAcceptAllFileFilterUsed(false);
            fileChooser.setFileSelectionMode(javax.swing.JFileChooser.DIRECTORIES_ONLY);
    
            jDialog1.setMinimumSize(new java.awt.Dimension(430, 260));
            jDialog1.setResizable(false);
    
            jLabel1.setText("Chemin des fichiers d'install :");
    
            parcourir.setText("Parcourir");
            parcourir.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    parcourirActionPerformed(evt);
                }
            });
    
            jLabel2.setText("VendorID (hexa 4 digit)");
    
            jLabel3.setText("ProductID (hexa 4 digit)");
    
            valider.setText("Valider");
            valider.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    validerActionPerformed(evt);
                }
            });
    
            cancel.setText("Annuler");
            cancel.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    cancelActionPerformed(evt);
                }
            });
    
            javax.swing.GroupLayout jDialog1Layout = new javax.swing.GroupLayout(jDialog1.getContentPane());
            jDialog1.getContentPane().setLayout(jDialog1Layout);
            jDialog1Layout.setHorizontalGroup(
                jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jDialog1Layout.createSequentialGroup()
                    .addGroup(jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jDialog1Layout.createSequentialGroup()
                            .addGap(33, 33, 33)
                            .addGroup(jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(vidField)
                                .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGap(10, 10, 10)
                            .addGroup(jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jDialog1Layout.createSequentialGroup()
                                    .addGap(112, 112, 112)
                                    .addComponent(cancel))
                                .addGroup(jDialog1Layout.createSequentialGroup()
                                    .addGap(89, 89, 89)
                                    .addGroup(jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(pidField, javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                            .addGap(23, 23, 23))
                        .addGroup(jDialog1Layout.createSequentialGroup()
                            .addContainerGap()
                            .addGroup(jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(valider)
                                .addComponent(jLabel1))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(fileField, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(parcourir)))
                    .addContainerGap(18, Short.MAX_VALUE))
            );
            jDialog1Layout.setVerticalGroup(
                jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jDialog1Layout.createSequentialGroup()
                    .addGap(22, 22, 22)
                    .addGroup(jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel1)
                        .addComponent(fileField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(parcourir))
                    .addGap(42, 42, 42)
                    .addGroup(jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(vidField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(pidField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel2))
                    .addGap(48, 48, 48)
                    .addGroup(jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(valider)
                        .addComponent(cancel))
                    .addContainerGap(25, Short.MAX_VALUE))
            );
    
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            setTitle("Crypteur de clé USB");
    
            jScrollPane1.setViewportView(validRootList);
    
            crypter.setText("Crypter");
            crypter.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    crypterActionPerformed(evt);
                }
            });
    
            quitter.setText("Quitter");
            quitter.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    quitterActionPerformed(evt);
                }
            });
    
            jTextArea1.setBackground(new java.awt.Color(204, 204, 204));
            jTextArea1.setColumns(20);
            jTextArea1.setEditable(false);
            jTextArea1.setRows(5);
            jTextArea1.setText( "Les clé suivantes vont être cryptées lorsque \n vous aurez cliqué sur le bouton \"Crypter\"\n\n masque VendorID=0x"+Integer.toHexString(vendorID)+"\n masque productID=0x"+Integer.toHexString(productID));
            jTextArea1.setBorder(null);
            jScrollPane2.setViewportView(jTextArea1);
    
            refresh.setText("Refresh");
            refresh.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    refreshActionPerformed(evt);
                }
            });
    
            modif.setText("Modif");
            modif.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    modifActionPerformed(evt);
                }
            });
    
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 144, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(refresh)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(modif)))
                    .addGap(64, 64, 64)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(crypter)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 90, Short.MAX_VALUE)
                            .addComponent(quitter)
                            .addGap(32, 32, 32))
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 230, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addContainerGap())))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(refresh)
                                .addComponent(modif))
                            .addGap(13, 13, 13)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 261, Short.MAX_VALUE))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 240, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 34, Short.MAX_VALUE)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(crypter)
                                .addComponent(quitter))))
                    .addContainerGap())
            );
    
            pack();
        }// </editor-fold>                        
    
    private void quitterActionPerformed(java.awt.event.ActionEvent evt) {                                        
        System.exit(0);
    }                                       
    
    private void crypterActionPerformed(java.awt.event.ActionEvent evt) {                                        
        processCrypt();
    }                                       
    
    private void refreshActionPerformed(java.awt.event.ActionEvent evt) {                                        
        actualiser();
    }                                       
    
    private void modifActionPerformed(java.awt.event.ActionEvent evt) {                                      
        fileField.setText(directory.toString());
        
        vidField.setText(""+Integer.toHexString(vendorID));
        pidField.setText(""+Integer.toHexString(productID));
        jDialog1.setVisible(true);
    }                                     
    
    private void parcourirActionPerformed(java.awt.event.ActionEvent evt) {                                          
        if(fileChooser.showOpenDialog(this)==JFileChooser.APPROVE_OPTION){
            tempDir = fileChooser.getCurrentDirectory();
            fileField.setText(tempDir.toString());
        }
    }                                         
    
    private void validerActionPerformed(java.awt.event.ActionEvent evt) {                                        
            FileOutputStream out = null;
            try {
                this.setCursor(Cursor.WAIT_CURSOR);
                directory = tempDir;
                vendorID = Integer.parseInt(vidField.getText(), 16);
                productID = Integer.parseInt(pidField.getText(), 16);
                File keys = new File("const.ini");
                keys.delete();
                out = new FileOutputStream(keys);
                out.write(vendorID);out.write('&');out.write(productID);out.write('\n');
                out.write(directory.getPath().getBytes("UTF8"));
                
                
                
                String str1 = "";
                for (int i = 0; i != key1.getEncoded().length; i++) {
                    str1 += (int) key1.getEncoded()[i];
                }
    
                jTextArea1.setText(" cliquer sur \"Crypter\" pour lancer le processus\n\n " + "masque VendorID=0x" + Integer.toHexString(vendorID) + "" + "\n masque productID=0x" + Integer.toHexString(productID) + "\n DES key : " + str1 + "\n\n les fichiers d'installation se trouvent dans : \n " + directory.toString());
    
                jDialog1.setVisible(false);
            } catch (FileNotFoundException ex) {
                Logger.getLogger(Crypter.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(Crypter.class.getName()).log(Level.SEVERE, null, ex);
            } finally {
                try {
                    out.close();                                       
                    
                } catch (IOException ex) {
                    Logger.getLogger(Crypter.class.getName()).log(Level.SEVERE, null, ex);
                }finally{
                    this.setCursor(Cursor.DEFAULT_CURSOR);
                }
            }
    }
    
    private void cancelActionPerformed(java.awt.event.ActionEvent evt) {                                       
        jDialog1.setVisible(false);
    }                                      
    
    
    
    private void actualiser(){
        if(!creating)
        this.setCursor(Cursor.WAIT_CURSOR);
        File report = new File("report");    
        try {
                cles=new ArrayList<USBKey>();
                keyRoot = new ArrayList<File>();
                Runtime runtime = Runtime.getRuntime();
    
                
                String[] command = {"cmd.exe", "/C", "usbdeview.exe /stext \"" + report.getName() + "\""};
                Process process = runtime.exec(command);
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException ex) {
                    System.out.println("cagade de thread");
                }
                ArrayList<USBKey> list = USButil.getConnectedUSBKeyList(report);
                if (list != null) {
                    for (int i = 0; i != list.size(); i++) {
                        if (list.get(i).getVendorID() == vendorID && list.get(i).getProductID() == productID) {
                            keyRoot.add(list.get(i).getAddress());
                            cles.add(list.get(i));
                        }
                    }
                } else {
                    System.out.println("Ca a foiré");
                }
                report.delete();
            } catch (IOException ex) {
                if(report.exists()){
                    report.delete();
                }
                ErrGlobale err = new ErrGlobale("Echec du refresh");
                err.setVisible(true);
            }finally{
                if(!creating)
                this.setCursor(Cursor.DEFAULT_CURSOR);
            }
    }
    
    private void processCrypt() {
          FileOutputStream stream = null;
          
          BufferedReader reader=null;
          this.setCursor(Cursor.WAIT_CURSOR);
       try {
          for(int i=0;i!=cles.size();i++){
            
                    byte[] b;
                    USBKey usb = cles.get(i);
                    System.out.println(usb.getSerialNumber());
                    b=usb.getSerialNumber().getBytes("UTF8");
                    String str = new String(b,"UTF8");
                    System.out.println(str);
                    for(int j=0;j!=b.length;j++){
                         System.out.print((char)b[j]+"   ");
                    }
                    File ini = new File(usb.getAddress().getAbsolutePath().concat("const.ini"));
                    File ini2= new File(usb.getAddress().getAbsolutePath().concat("licence.ini"));
                    stream = new FileOutputStream(ini);
                    //remplissage du fichier const.ini
                    stream.write(Integer.toHexString(vendorID).getBytes());
                    stream.write((int)'&');
                    stream.write(Integer.toHexString(productID).getBytes());
                    
                    //remplissage du fichier licence.ini
                    stream = new FileOutputStream(ini2);
                   
                    stream.write(getCleCrypte(usb.getSerialNumber()));
                    stream.close();
                    
                    
                    
                    System.out.println(str);
                    File copy= new File(usb.getAddress().getAbsolutePath()+"install"+"English"+"Francais");
                    copyFileTree(directory, copy);
                    
          }
          
       } catch (FileNotFoundException ex) {
       
           Logger.getLogger(Crypter.class.getName()).log(Level.SEVERE, null, ex);
       
       } catch (IOException ex) {
           
           Logger.getLogger(Crypter.class.getName()).log(Level.SEVERE, null, ex);
           
       } finally {
       
           try {
           
               stream.close();
               
           } catch (IOException ex) {
           
               Logger.getLogger(Crypter.class.getName()).log(Level.SEVERE, null, ex);
           
           }
                }
          this.setCursor(Cursor.DEFAULT_CURSOR);
    }
    
    
    
    private byte[] getCleCrypte(String serial){
    
                return cipher.encrypt(serial);   
    }
    
    
    
    /** 
     * copie l'arborescence des fichiers du source vers la destination
     */
    private static boolean copyFileTree(File source, File dest){
        boolean result=true;
    	FileChannel in = null; // canal d'entrée
            FileChannel out = null; // canal de sortie
            
        try {
      // Init
            if(source.isDirectory()){
                File[] files = source.listFiles();
                dest.mkdir();
                File dest2;
                for(int i=0;i!=files.length;i++){
                    dest2= new File(dest.getAbsolutePath()+"/"+files[i].getName());
                    result = result && copyFileTree(files[i],dest2);
                }
            }else{
                in = new FileInputStream(source).getChannel();
                out = new FileOutputStream(dest).getChannel();
           
                // Copie depuis le in vers le out
                in.transferTo(0, in.size(), out);
            }
        } catch (Exception e) {
            e.printStackTrace(); // n'importe quelle exception
            result= false;
        } finally { // finalement on ferme
            if(in != null) {
                try {
                    in.close();
                } catch (IOException e) {}
            }
            if(out != null) {
                try {
                    out.close();
                } catch (IOException e) {}
            }
            return result;
           
        }
    }
    
        /**
        * @param args the command line arguments
        */
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    
                    FileInputStream stream=null;
                    InputStreamReader in=null;
                    BufferedReader reader=null;
                    try {
                        
                        int vendorID;
                        int productID;
                        
                        File keys = new File("const.ini");
                        stream = new FileInputStream(keys);
                        in= new InputStreamReader(stream);
                        reader= new BufferedReader(in);
                        String keyLine= reader.readLine();
                        
                        String[] keySplit = keyLine.split("&");
                        vendorID=Integer.parseInt(keySplit[0],16);
                        productID=Integer.parseInt(keySplit[1],16);
                        String path = reader.readLine();
                        File installFilesPath= new File(path);
                        new Crypter(vendorID, productID, installFilesPath).setVisible(true);
                        
                    } catch (Exception ex) {
                        ErrGlobale err = new ErrGlobale("le fichier const.ini a chié dans la colle");
                        err.setVisible(true);
                    } finally {
                        try {
                            if(stream!=null)
                                stream.close();
                            if(in!=null)
                                in.close();
                            if(reader!=null)
                                reader.close();
                            
                        } catch (IOException ex) {
                            Logger.getLogger(Crypter.class.getName()).log(Level.SEVERE, null, ex);
                        }
                    }
                }
            });
            
           
    //           
        }
    
        // Variables declaration - do not modify                     
        private javax.swing.JButton cancel;
        private javax.swing.JButton crypter;
        private javax.swing.JFileChooser fileChooser;
        private javax.swing.JTextField fileField;
        private javax.swing.JDialog jDialog1;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JLabel jLabel2;
        private javax.swing.JLabel jLabel3;
        private javax.swing.JScrollPane jScrollPane1;
        private javax.swing.JScrollPane jScrollPane2;
        private javax.swing.JTextArea jTextArea1;
        private javax.swing.JButton modif;
        private javax.swing.JButton parcourir;
        private javax.swing.JTextField pidField;
        private javax.swing.JButton quitter;
        private javax.swing.JButton refresh;
        private javax.swing.JList validRootList;
        private javax.swing.JButton valider;
        private javax.swing.JTextField vidField;
        // End of variables declaration                   
    
    }
    


    quelqun pourrais me guider dans se que je devrais changer pour copier ses deux fichier dans à l'endroit voulu?
    J'utilise le logiciel Netbeans.

    Je vous remercie d'avance (et ne vous demande en aucun cas de faire le travail à ma place mais je souhaiterais juste être guider :euh: )
    • Partager sur Facebook
    • Partager sur Twitter
      5 mai 2010 à 11:03:24

      Bonjour,
      en fait c'est assez simple,
      une fois que tu auras localisé l'écriture des fichiers (bonne chance :p ), tu dois trouvé un paramètre qui est l'endroit où écrire le fichier et donc tu mets "c:/english" ou "c:/francais" comme tu veux.
      Si les dossier n'existe pas tu peux les créer avec
      new File("c:/english").mkdir();
      


      sauf que bien sûr tout les 'c:' sont à remplacer par ta racine

      Edit : en fait c'est soit à l'écriture, soit à la création du fichier
      • Partager sur Facebook
      • Partager sur Twitter
        5 mai 2010 à 11:27:10

        J'ai trouvé la partie de code qui copie les fichiers dans la clée USB :

        File ini = new File(usb.getAddress().getAbsolutePath().concat("const.ini"));
                        File ini2= new File(usb.getAddress().getAbsolutePath().concat("licence.ini"));
                        stream = new FileOutputStream(ini);
                        //remplissage du fichier const.ini
                        stream.write(Integer.toHexString(vendorID).getBytes());
                        stream.write((int)'&');
                        stream.write(Integer.toHexString(productID).getBytes());
                        
                        //remplissage du fichier licence.ini
                        stream = new FileOutputStream(ini2);
                       
                        stream.write(getCleCrypte(usb.getSerialNumber()));
                        stream.close();
                        
                        
                        
                        System.out.println(str);
                        File copy= new File(usb.getAddress().getAbsolutePath()+"install");
                        copyFileTree(directory, copy);
        


        usb.getAddress().getAbsolutePath() correspond a ma clée usb il me semble, ou placer le code pour copier les fichiers dans les deux dossier de ma clée usb?
        • Partager sur Facebook
        • Partager sur Twitter
          5 mai 2010 à 11:37:25

          tu mets juste le nom de ton dossier là :
          File ini2= new File(usb.getAddress().getAbsolutePath().concat("nomDossier/licence.ini"));
          


          il faut bien sûr que ton dossier "nomDossier" existe.

          après il y a les fameux problèmes de '/', '\', '\\', ...
          mais ça avec des essais tu résout le problème (si tu l'as assez facilement
          • Partager sur Facebook
          • Partager sur Twitter

          Copier deux fichier dans deux dossier différents

          × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
          × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
          • Editeur
          • Markdown