项目中要生成pdf文件,PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStrea(D://ITextTest.pdf));window中可以指定到D盘,现在项目要发布到liunx中,不能直接给指定路径,该问题如何解决?

解决方案 »

  1.   

     liunx中没有盘符,PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("ITextTest.pdf"));这样不指定盘符??? 
      

  2.   

    在linux上么就写linux的路径格式不就完了嘛
      

  3.   

    判断os是windows还是linux就好了,这样取出的路径,跟os就没有关系了,移植之后,也就不用改code了。
    String rootPath = request.getSession().getServletContext().getRealPath("/");
    Properties prop = System.getProperties();
    String os = prop.getProperty("os.name");
    if(os.toLowerCase().indexOf("windows") != -1){//windows
      filePath = rootPath + "\\";
    }else if(os.toLowerCase().equals("linux")){//Linux
      filePath = rootPath + "/";
    }
      

  4.   

    linux中怎么不能指定路径?例如:指定到/usr/home文件夹下
    new FileOutputStrea(\usr\home\ITextTest.pdf)
      

  5.   


    lz意思應該是,路徑不能寫死。 最好是把路徑寫在配置檔中,
    再寫方法來區分os,這樣日後改的code會非常少而方便。
    判断os是windows还是linux就好了,这样取出的路径,跟os就没有关系了,移植之后,也就不用改code了。
    String rootPath = request.getSession().getServletContext().getRealPath("/");
    Properties prop = System.getProperties();
    String os = prop.getProperty("os.name");
    if(os.toLowerCase().indexOf("windows") != -1){//windows
      filePath = rootPath + "\\";
    }else if(os.toLowerCase().equals("linux")){//Linux
      filePath = rootPath + "/";
    }