我猜楼主是直接写在main里面print出来的吧?
放在web application里面试试看?
@_@

解决方案 »

  1.   

    你用new File("filepath/filename");的方式
    如果不能从该filepath中找到这个名为filename的文件
    则会创建一个新的文件,等待被写入。如果此时调用System.out.println(f.exists());
    应该可以看到显示的是false,即该文件在硬盘中是不存在的想要正确找到classes目录下的文件,可以用这样的方式:
    URL fileURL = Thread.currentThread().getContextClassLoader().getResource("log4j.properties");
    File file = new File(fileURL.getFile());
      

  2.   

    如果你是在Servlet中读取,则可以
    InputStream log4j = InitServlet.class.getResourceAsStream(
            "/log4j.properties");
    Properties props = new Properties();
    props.load(log4j);
    org.apache.log4j.PropertyConfigurator.configure(props);