//For Window 需要用反斜杠

    private String path = "..\\webapps\\ROOT\\upload\\documents\\";

    //For Other OS 需要用正斜杠

    private String path2 = "/opt/tomcat/webapps/ROOT/upload/documents/";

    //getBasedir() 和 getSeparator()定义了在不同操作系统下的路径或连接符

    private String Basedir,Separator;
    
    public String getSeparator()
    {
        if(Separator==null)
        {
            String osName = System.getProperty("os.name");
            if(osName == null)
                osName="";
            if(osName.toLowerCase().indexOf("win") != -1)
                Separator = "\\";
            else
                Separator = "/";
        }
        return Separator;
    }
    public String getBasedir()
    {
        if(Basedir==null)
        {
            String osName = System.getProperty("os.name");
            if(osName == null)
                osName="";
            if(osName.toLowerCase().indexOf("win") != -1)
                Basedir = path;
            else
                Basedir = path2;
        }
        return Basedir;
    }
    // 一个完整的文件路径
    String storedir = getBasedir() + "data" +getSeparator();

相关文章:

  • 2021-10-06
  • 2021-11-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-19
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-30
  • 2022-12-23
  • 2021-07-27
  • 2021-06-17
相关资源
相似解决方案