根据系统创建文件路径,免得来回更改代码
public String createFile(String fileName, HttpServletRequest request) {
Properties props = System.getProperties(); // 获得系统属性集
String osName = props.getProperty("os.name"); // 操作系统名称
String filePath = "";
String path = "";
if(osName.startsWith("Linux")){
path = File.separator + "usr" + File.separator + "apps" + File.separator + "objecttemp" + File.separator + "sip" + File.separator ;// 形成元数据路径
File file = new File(path);
if (!file.exists()) {
file.mkdirs(); // 生成文件夹
}
filePath = path + fileName;
}else if(osName.startsWith("Windows")){
String projectPath = request.getSession().getServletContext().getRealPath("/"); //项目所在目录
if (!path.endsWith(File.separator)) {
path += File.separator;
}
path = projectPath + "xmlFiles" + File.separator + "xml" + File.separator;// 形成元数据路径
File file = new File(path);
if (!file.exists()) {
file.mkdirs(); // 生成文件夹
}
filePath = path + fileName;
}
return filePath;
}