elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Los 10 CVE más críticos (peligrosos) de 2020


  Mostrar Mensajes
Páginas: [1]
1  Programación / Java / REALIZAR LA COPIA DE UNA FOTO EN UN DIRECTORIO en: 16 Noviembre 2009, 02:44 am
package archivos;
import java.io.*;
//import java.util.*;

public class Archivo {
    public static void Copiar(String file1, String file2)throws Exception{
      
      //Abrir los archivos
                File f1 = new File(file1);
      File f2 = new File(file2);
      if(f1.exists()){
                    //Enviar datos
                    FileInputStream fis = new FileInputStream(f1);
                    //Da todos los metodos para leer del origen
                    DataInputStream dis = new DataInputStream(fis);
                    //Recibir datos
                    FileOutputStream fos = new FileOutputStream(f2);
                    //Da todos los metodos que DataIS pero en Write
                    DataOutputStream dos = new DataOutputStream(fos);
                    int c;
                    while(true){//Leo desd el origen
                        //Lee bite x bite y guardo en c
                        c=dis.read();
                        if(c==-1)break;
                        dos.write(c);//escribo en el destino
                    }
                    dis.close();
                    dos.close();
                }else{
                    System.out.println("No existe el archivo");
                }
      }
   
    public static void main(String args[])
    throws FileNotFoundException, IOException, Exception{
        String source = "c:\\foto.jpg";
        String target = "c:\\Copiafoto.jpg";
        Archivo.Copiar(source, target);
    }
   
    public Archivo() {
    }   
}
 ;-)
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines