Foro de elhacker.net

Programación => Java => Mensaje iniciado por: OsmaK en 19 Diciembre 2015, 16:20 pm



Título: Ayuda! Copiar y pegar archivos .mp4 con java
Publicado por: OsmaK en 19 Diciembre 2015, 16:20 pm
Hola! Soy nuevo en Java y estoy haciendo un programa en el que en un JFrame te pide cargar un vídeo, quiero que salga una interfaz en la que buscar el vídeo y posteriormente ese mismo vídeo en formato mp4 sea copiado a un directorio establecido de forma predeterminada, gracias!

Uso Eclipse


Título: Re: Ayuda! Copiar y pegar archivos .mp4 con java
Publicado por: 0xFer en 19 Diciembre 2015, 17:55 pm
Para seleccionar el fichero usa JFileChooser, para copiar el fichero a otra carpeta usa este código de http://www.java-tips.org/

Código
  1. // If targetLocation does not exist, it will be created.
  2. public void copyDirectory(File sourceLocation , File targetLocation)
  3. throws IOException {
  4.  
  5.     if (sourceLocation.isDirectory()) {
  6.         if (!targetLocation.exists()) {
  7.             targetLocation.mkdir();
  8.         }
  9.  
  10.         String[] children = sourceLocation.list();
  11.         for (int i=0; i<children.length; i++) {
  12.             copyDirectory(new File(sourceLocation, children[i]),
  13.                     new File(targetLocation, children[i]));
  14.         }
  15.     } else {
  16.  
  17.         InputStream in = new FileInputStream(sourceLocation);
  18.         OutputStream out = new FileOutputStream(targetLocation);
  19.  
  20.         // Copy the bits from instream to outstream
  21.         byte[] buf = new byte[1024];
  22.         int len;
  23.         while ((len = in.read(buf)) > 0) {
  24.             out.write(buf, 0, len);
  25.         }
  26.         in.close();
  27.         out.close();
  28.     }
  29. }