Copia seguridad en Java

 Seguidamente se muestra como hacer copia de carpetas de un origen a destino en Java. Sino existe la carpeta la crea. Son dos ficheros: Backup.java y FileUtils.java

Backup.java
=====================================================
package backup;

import java.io.File;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.logging.Level;
import java.util.logging.Logger;

public class Backup {
 public static void main(String[] args) {

        try {
            DateFormat dateFormat = new SimpleDateFormat(«yyyy-MM-dd»);
            Calendar cal = Calendar.getInstance();
            String dia = dateFormat.format(cal.getTime());

            File srcDir;
            File destDir;
            FileUtils fileUtils;
            fileUtils = new FileUtils();
            int contador = 1;

            System.out.println(«Fecha: » + dia);

            srcDir = new File(«C:\Users\Paco\Documents\Fuente»);
            destDir = new File(«C:\Users\Paco\Documents\backup\» + dia + «\Fuente»);
            fileUtils.copyDirectory(srcDir, destDir);
            System.out.println(contador + «. Copiado » + srcDir + » » + » en » + destDir);
           
        } catch (IOException ex) {
            Logger.getLogger(Backup.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

}
FileUtils.java
=====================================================
package backup;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

class FileUtils {

    public void copy(File sourceLocation, File targetLocation) throws IOException {
        if (sourceLocation.isDirectory()) {
            copyDirectory(sourceLocation, targetLocation);
        } else {
            copyFile(sourceLocation, targetLocation);
        }
    }

    void copyDirectory(File source, File target) throws IOException {
        File destino;
        File origen;

        if (!target.exists()) {
            //target.mkdir();
            target.mkdirs(); // Crea carpetas sino existe
        }

        for (String f : source.list()) {
            origen = new File(source, f);
            destino = new File(target, f);
            if ((origen.lastModified() > destino.lastModified()) || (origen.length() > destino.length())) {
                copy(origen, destino);
            }
        }
    }

    private void copyFile(File source, File target) throws IOException {
        try (
                InputStream in = new FileInputStream(source);
                OutputStream out = new FileOutputStream(target)) {
            byte[] buf = new byte[1024];
            int length;
            while ((length = in.read(buf)) > 0) {
                out.write(buf, 0, length);
            }
        }
    }
}

Fuente:
https://stackoverflow.com/questions/5368724/how-to-copy-a-folder-and-all-its-subfolders-and-files-into-another-folder

FIREFOX JAVA UBUNTU

1) Test Java. Podemos ver si funciona java en:
http://www.java.com/es/download/help/testvm.xml

http://www.javatester.org/version.html

2) Firefox. Ver los plugins en:
about:plugins

3) Plugin Instalación:
http://plugindoc.mozdev.org/linux.html#Java

Java Runtime Environment
Version: 1.4.2 or later
SeaMonkey 1.0: Supported
Firefox 2.0: Supported
FAQ: Java FAQ

1. Install Java Runtime Environment.
2. Make a symbolic link to libjavaplugin_oji.so in your Mozilla Plugins directory. Use the copy located in the plugin/i386/ns7 directory of JRE 5.0 or later, or plugin/i386/ns610-gcc32 if you are using JRE 1.4.2.

Important! Do not copy the plugin to your plugins directory. If you do, Mozilla will crash any time you attempt to view a page containing a Java applet.

4)Instalar java:

Dercargando archivo: jre-6u19-linux-i586.bin

De la web: http://www.java.com/es/download/linux_manual.jsp?locale=es&host=www.java.com

Desde los repositorios:
sudo aptitude install jamvm openjdk-6-jre-headless sun-java6-jre sun-java6-plugin sun-java6-fonts

5) Arreglar enlaces:
ln -s /usr/lib/jvm/jre1.6.0_18/plugin/i386/ns7/libjavaplugin_oji.so $HOME/firefox/plugins/
sudo ln -s /usr/lib/jvm/jre1.6.0_18/plugin/i386/ns7/libjavaplugin_oji.so /usr/lib/firefox/plugins/

6) Ver plugins aplicados:
sudo galternatives