目的是在类的代码里建立一个文件,并向其中写入内容。我获取路径的方法是:            String path = LogManage.class.getResource("/").getPath().substring(1);
            path = path.substring(0,path.indexOf("classes/"));
            Calendar c = Calendar.getInstance(); 
            String year = ""+c.get(Calendar.YEAR);
            String month = ""+c.get(Calendar.MONTH);
            String day = ""+c.get(Calendar.DATE);
            path += "logs";
            File f = new File(path);
            if(!f.exists()) 
            f.mkdirs(); 
            path += "/"+year+"-"+month+"-"+day+"-logtemp.log";
            File file = new File(path);目的是在WEB-INF下面的log文件夹下建立文件。原来项目在windows下部署,没有问题。现在要迁移到linux下面的时候,文件写的地方错了。写在了usr/localhost/tomcat/bin/usr/localhost/tomcat/webapps/fsclient/web-inf/logs下面也就是路径多写入了一个从linux用户文件夹到tomcat的路径。。怎么可以让文件再写在usr/localhost/tomcat/webapps/fsclient/web-inf/logs这个文件夹下啊谢谢了

解决方案 »

  1.   

    路径应该是这样的:/usr/localhost/tomcat/webapps/fsclient/web-inf/logs
      

  2.   

    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path1 + "/";
    String path1 = request.getContextPath();
    试试这两个看能不能得到
      

  3.   

    不行- -#  我用            String path = System.getProperty("user.dir");
                path = path.substring(0,path.lastIndexOf("/"));
                path += "/webapps/fsclient/WEB-INF/logs";获取到了,但是很不好,因为路径是死的,如果修改了应用名以后就会出错- -# 不知道有没有什么更好的办法没???