//For Window 需要用反斜杠
private String path = "..\\webapps\\ROOT\\upload\\documents\\";
private String path2 = "/opt/tomcat/webapps/ROOT/upload/documents/";
//getBasedir() 和 getSeparator()定义了在不同操作系统下的路径或连接符
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();