Advertisement
Metziop

metodo renomrar

Apr 29th, 2021
839
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.43 KB | None | 0 0
  1. private void btnLoad4ActionPerformed(java.awt.event.ActionEvent evt) {                                        
  2.        //creamos el objeto JFileChooser
  3.         JFileChooser seleccion = new JFileChooser();
  4.         seleccion.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
  5.        
  6.         int val = seleccion.showOpenDialog(null);        
  7.         //asignamos el archivo seleccionado al directorio
  8.         if (val == JFileChooser.OPEN_DIALOG) {
  9.             String pathAbsoluto = seleccion.getSelectedFile().getAbsolutePath();
  10.             String directorioActual = seleccion.getCurrentDirectory().getPath();
  11.             //mostrar la ruta actual
  12.             JOptionPane.showMessageDialog(null, "Directorio: " + pathAbsoluto+ "  path: "+directorioActual);
  13.             String respuesta;
  14.             respuesta = JOptionPane.showInputDialog("Como indique el nuevo nombre del archivo");
  15.            
  16.             //renombrando el archivo actual
  17.             boolean isArchivoRenombrado = seleccion.getSelectedFile().renameTo(new File(directorioActual +"//"+ respuesta+".txt"));
  18.            
  19.  
  20.             //Confirmacion
  21.             if (isArchivoRenombrado){
  22.                 JOptionPane.showMessageDialog(null, "El archivo renombrado de forma correcta");
  23.             }
  24.            
  25.         } else if (val == JFileChooser.CANCEL_OPTION) {
  26.             JOptionPane.showMessageDialog(null, "Proceso cancelado ");
  27.         }
  28.     }                    
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement