Ver Mensaje Individual
  #2 (permalink)  
Antiguo 31/12/2012, 13:48
Doctrina
 
Fecha de Ingreso: abril-2012
Ubicación: Canarias
Mensajes: 41
Antigüedad: 12 años
Puntos: 5
Respuesta: Copiar ficheros

Hoy no es mi día y seguro que alguno de mis compañeros podrá darte una forma más eficiente de hacer lo que pides. Pero al día y la hora a la que estamos y sin pensar demasiado esto es lo que se me ocurrió, servir sirve, pero puede que haya maneras mejores:

Código Java:
Ver original
  1. try {
  2.             PrintWriter writer = new PrintWriter(new FileOutputStream(new File("/home/diego/Escritorio/hola-copiado.txt")));
  3.            
  4.             BufferedReader reader = new BufferedReader(new FileReader(new File("/home/diego/Escritorio/hola.txt")));
  5.            
  6.             String line;
  7.             while((line = reader.readLine()) != null)
  8.                 {
  9.                 writer.write(line+"\n");
  10.                 }
  11.        
  12.             writer.close();
  13.             reader.close();
  14.            
  15.         } catch (FileNotFoundException e) {
  16.             e.printStackTrace();
  17.         }
  18.         catch(IOException e)
  19.         {
  20.             e.printStackTrace();
  21.         }