java.io.FileNotFoundException:/Escritorio/pdf_tabla_Clientes.pdf(没有这样的文件或目录)

时间:2014-04-04 01:13:37

标签: java swing file-io filenotfoundexception fileoutputstream

我无法将我桌面的路径放在我的mac中以保存pdf。

  

java.io.FileNotFoundException:/Escritorio/pdf_tabla_Clientes.pdf(否)   这样的文件或目录)在java.io.FileOutputStream.open(Native   方法)在java.io.FileOutputStream。(FileOutputStream.java:194)     在java.io.FileOutputStream。(FileOutputStream.java:84)at   GenerarPDFEmpleados。(GenerarPDFEmpleados.java:58)at   报告$ 1.actionPerformed(Reportes.java:61)at   javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2028)     在   javax.swing.AbstractButton中的$ Handler.actionPerformed(AbstractButton.java:2351)     在   javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)     在   javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)     在   javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)     在java.awt.Component.processMouseEvent(Component.java:6414)at   javax.swing.JComponent.processMouseEvent(JComponent.java:3275)at   java.awt.Component.processEvent(Component.java:6179)at   java.awt.Container.processEvent(Container.java:2084)at   java.awt.Component.dispatchEventImpl(Component.java:4776)at   java.awt.Container.dispatchEventImpl(Container.java:2142)at   java.awt.Component.dispatchEvent(Component.java:4604)at   java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4618)     在   java.awt.LightweightDispatcher.processMouseEvent(Container.java:4279)     at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4209)     在java.awt.Container.dispatchEventImpl(Container.java:2128)at   java.awt.Window.dispatchEventImpl(Window.java:2492)at   java.awt.Component.dispatchEvent(Component.java:4604)at   java.awt.EventQueue.dispatchEventImpl(EventQueue.java:717)at at   java.awt.EventQueue.access $ 400(EventQueue.java:82)at   java.awt.EventQueue $ 2.run(EventQueue.java:676)at   java.awt.EventQueue $ 2.run(EventQueue.java:674)at   java.security.AccessController.doPrivileged(Native Method)at   java.security.AccessControlContext $ 1.doIntersectionPrivilege(AccessControlContext.java:86)     在   java.security.AccessControlContext $ 1.doIntersectionPrivilege(AccessControlContext.java:97)     在java.awt.EventQueue $ 3.run(EventQueue.java:690)at   java.awt.EventQueue $ 3.run(EventQueue.java:688)at   java.security.AccessController.doPrivileged(Native Method)at   java.security.AccessControlContext $ 1.doIntersectionPrivilege(AccessControlContext.java:86)     在java.awt.EventQueue.dispatchEvent(EventQueue.java:687)at   java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)     在   java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)     在   java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)     在   java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)     在   java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)     在java.awt.EventDispatchThread.run(EventDispatchThread.java:122)e

继承我的代码:

public class GenerarPDFEmpleados
{
    private String strNombreDelPDF;

    private  Font fuenteNegra10 = new Font();
    private  Font fuente8 = new Font();
    private  Font fuenteAzul25 = new Font();

    Color grisClaro = new Color( 230,230,230);  
    Color azulClaro = new Color( 124,195,255 );

    //############# VARIABLES PARA MANEJO DE BASE DE DATOS ########################
    //Guarda la consulta operacion a realizar
    String strConsultaSQL;
    //Apuntador a la conexion
    Connection conn = null; 
    //Para ejecutar operaciones SQL
    Statement estSQL1;
    //Para guardar los resultados de una operacion SELECT
    ResultSet rs;
    Document document;
    PdfWriter writer;
    String strRotuloPDF;

    //Metodo principal del ejemplo
    public GenerarPDFEmpleados(String titulo, String nomPDF)
    {
        strRotuloPDF = titulo;
        strNombreDelPDF = nomPDF;
        try
        {       //Hoja tamanio carta, rotarla (cambiar a horizontal)
            document = new Document( PageSize.LETTER.rotate() );

            writer = PdfWriter.getInstance(
            // that listens to the document
                    document,
                    // direccionar el PDF-stream a un archivo
                    new FileOutputStream("/Escritorio/"+strNombreDelPDF));
            document.open();

            agregarMetaDatos(document);
            agregarContenido(document);

            document.close();

            System.out.println("Se ha generado el PDF: "+ strNombreDelPDF);

        } catch (Exception e) 
        {
            e.printStackTrace();
        }
    }

0 个答案:

没有答案