Ir al contenido principal

Java Mover un Archivo a otra Carpeta - File.java

Clase Demo para mover archivos de un directorio a otro directorio.

public class DemoFileJava {
public static void main(String[] args) throws Exception {

HelperSID.validateDir("C:\\IBM\\a\\", true);
HelperSID.fileMove("C:\\Aged Receivables.xls",
"C:\\IBM\\a\\Aged Receivables.xls");
}

public static void fileMove(String sourceFile, String destinationFile) {
System.out.println("Desde: " + sourceFile);
System.out.println("Hacia: " + destinationFile);

try {
File inFile = new File(sourceFile);
File outFile = new File(destinationFile);

FileInputStream in = new FileInputStream(inFile);
FileOutputStream out = new FileOutputStream(outFile);

int c;
while ((c = in.read()) != -1)
out.write(c);

in.close();
out.close();

File file = new File(sourceFile);
if (file.exists()) {
file.delete();
}

} catch (IOException e) {
System.err.println("Hubo un error de entrada/salida!!!");
}
}

public static boolean validateDir(String path, boolean action) {
File file = new File(path);
boolean isDirectory = file.isDirectory();
if (action)
file.mkdirs();
return isDirectory;
}

}

Comentarios

  1. gracias fue de mucha utilidad

    ResponderEliminar
  2. Gracias, justo lo que necesitaba.

    ResponderEliminar
  3. No sea tan hp esa mierda no sirve

    ResponderEliminar
  4. Esta perfecto, pero solo le falta una cosa:

    outFile.createNewFile();

    antes de...

    FileInputStream in = new FileInputStream(inFile);
    FileOutputStream out = new FileOutputStream(outFile);

    Si no te da el problema de que no encuentra el archivo destino.

    Espero que os sirva ;)

    ResponderEliminar
  5. Gracias por tu aporte. Me gustaria que me ayudaras en la parte de
    "HelperSID.validateDir("C:\\IBM\\a\\", true);
    HelperSID.fileMove("C:\\Aged Receivables.xls","
    pues no entiendo esa parte y ademas me tira error.
    Desde ya gracias por las respuestas.

    ResponderEliminar

Publicar un comentario

Entradas populares de este blog

Java POI HSSFCell : añadir comentario en una celda

POI HSSFComment: Una manera simple de añadir un comentario en una celda de excel usando el metodo cell.setCellComment(). public class ExcelTools { public static void main(String[] args){ //escribirExcel(); //leerExcel(); validarValoresDuplicadosLista(); System.out.println("Ejemplo Finalizado."); } public static void escribirExcel(){ try{ //Se crea el libro Excel HSSFWorkbook wb = new HSSFWorkbook(); //Se crea una nueva hoja dentro del libro HSSFSheet sheet = wb.createSheet("HojaEjemplo"); //Se crea una fila dentro de la hoja HSSFRow row = sheet.createRow((short)0); HSSFPatriarch patr = sheet.createDrawingPatriarch(); //Creamos celdas de varios tipos row.createCell((short)0).setCellValue(1); row.createCell((short)1).setCellValue(1.2); row.createCell((short)2).setCellValue("ejemplo&

Debugging Remoto con Eclipse + WebSphere 7 + Maven

Tienes proyectos java en Maven y no puedes ubicar bugs fácilmente a falta de junit. Sin embargo, existe la alternativa de debugear la aplicación web a través de Java Debugger (jdb). Aquí les muestro una guía de como hacer un debug remoto de la aplicación web en Eclipse y WebSphere 7 a través de Java Debugger (JDB). Eclipse <----> Java Debugger (jdb) <----> WebSphere 7 1. Habilitar el WebSphere en modo Debug. Para esto seguir los siguientes pasos:  1. Servers –> Server Types –> WebSphere application servers 2. Under Server Infrastructure section –> expandir Java and Process Management –> Process definition 3. dentro de la seccion Additional Properties –> click Java Virtual Machine 4. clic en el check “Debug Mode” 5. En texbox Debug arguments, poner este valor:  -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8888 6. Reiniciar el servidor WebSphere. Ahora, WebSphere se inicia en modo debug, y escuchando en el pu

DB2 Error SQL20054N

Ejecutando un alter table me da el  siguiente error: db2 "ALTER TABLE PRG_REC.ESTIMADO_OBJETIVO DROP COLUMN VTA_OBJ_CAMP_FALTA_EXTRANJERA"; Error:  [db2inst1@ibmdb2test]:/home/db2inst1/1223/REQ1223/rollback$ db2 "ALTER TABLE PRG_REC.ESTIMADO_OBJETIVO DROP COLUMN VTA_OBJ_CAMP_FALTA_EXTRANJERA"; DB21034E  The command was processed as an SQL statement because it was not a valid Command Line Processor command.  During SQL processing it returned: SQL20054N  The table "PRG_REC.ESTIMADO_OBJETIVO" is in an invalid state for the operation.  Reason code="23" .  SQLSTATE=55019 Segun IBM la descripcion del error: SQL20054N:  La tabla   nombre-tabla   está en un estado no válido para la operación. Código de razón= código-razón . 23 Se ha realizado el número máximo de modificaciones recomendadas de REORG. Se permite un máximo de tres modificaciones recomendadas de REORG en una tabla antes de que se deba realizar reorg, para actualizar las fila