Ver Mensaje Individual
  #6 (permalink)  
Antiguo 28/12/2014, 11:01
Avatar de iDEVELOPwithGNUlinux
iDEVELOPwithGNUlinux
 
Fecha de Ingreso: febrero-2012
Mensajes: 27
Antigüedad: 12 años, 3 meses
Puntos: 0
Respuesta: ¿Cómo asigno un fichero PDF a un diálogo de "Guardar como"?

Bien, he resuelto el problema yo mismo con este código.

Código:
JFileChooser JFCO = new JFileChooser();
            File f2 = new File(System.getProperty("user.dir"), "FICHERACO.pdf");
 
            JFCO.setCurrentDirectory(new File(System.getProperty("user.dir")));
            
            JFCO.setSelectedFile(f2);

            JFCO.setFileSelectionMode(JFileChooser.FILES_ONLY);

            int returnVal = JFCO.showSaveDialog(null);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                File fC = new File(JFCO.getSelectedFile().getAbsolutePath());
                InputStream in = new FileInputStream(f2);

                OutputStream out = new FileOutputStream(fC);

                byte[] buf = new byte[1024];
                int len;
                while ((len = in.read(buf)) > 0) {
                    out.write(buf, 0, len);
                }
                in.close();
                out.close();
            }
            
            f2.delete();
Con esto copio el fichero de origen y luego lo elimino. Es una chapuza, pero funciona .