Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void btnLoad4ActionPerformed(java.awt.event.ActionEvent evt) {
- //creamos el objeto JFileChooser
- JFileChooser seleccion = new JFileChooser();
- seleccion.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
- int val = seleccion.showOpenDialog(null);
- //asignamos el archivo seleccionado al directorio
- if (val == JFileChooser.OPEN_DIALOG) {
- String pathAbsoluto = seleccion.getSelectedFile().getAbsolutePath();
- String directorioActual = seleccion.getCurrentDirectory().getPath();
- //mostrar la ruta actual
- JOptionPane.showMessageDialog(null, "Directorio: " + pathAbsoluto+ " path: "+directorioActual);
- String respuesta;
- respuesta = JOptionPane.showInputDialog("Como indique el nuevo nombre del archivo");
- //renombrando el archivo actual
- boolean isArchivoRenombrado = seleccion.getSelectedFile().renameTo(new File(directorioActual +"//"+ respuesta+".txt"));
- //Confirmacion
- if (isArchivoRenombrado){
- JOptionPane.showMessageDialog(null, "El archivo renombrado de forma correcta");
- }
- } else if (val == JFileChooser.CANCEL_OPTION) {
- JOptionPane.showMessageDialog(null, "Proceso cancelado ");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement