如果想在一个web工程中用java生成一个文件,则获得服务器的绝对路径的方法如下:
如现如用tomcat(或其他)服务器,将该文件保存到代码工程的 WebRoot/excelFile中
String dir = ServletActionContext.getServletContext().getRealPath( "/excelFile/new.xls");
若tomcat的所在路径为D:\Program Files\apache-tomcat-6.0.14
则 变量dir的值即为D:\Program Files\apache-tomcat-6.0.14\webapps\工程名\excelFile\new.xls