package com.sinosoft.common.util; import java.io.File; import java.io.IOException; import java.util.Properties; import org.apache.log4j.Logger; public class FilePathUtil { private static final Logger log = Logger.getLogger(FilePathUtil.class); /** * 根据不同操作系统获取不同文件上传或下载路径 * @return String path * @throws IOException */ public static String getUploadPath() throws IOException{ String result = ""; Properties props = new Properties(); java.io.InputStream in = FilePathUtil.class .getResourceAsStream("../../../../fileupdown.properties"); props.load(in); in.close(); String winpath = props.getProperty("winpath"); String linuxpath = props.getProperty("linuxpath"); Properties sysprops = System.getProperties(); String osName = sysprops.getProperty("os.name"); if(osName.startsWith("win")||osName.startsWith("Win")){//windows系统 result = winpath; //result = "D:\\upload\\aaa"; }else if(osName.startsWith("linux")||osName.startsWith("Linux")){//linux系统 result = linuxpath; }else{ result = winpath; } File file = new File(result); if(!file.exists()){//文件夹不存在,则创建 boolean flag = file.mkdirs(); if(!flag){ log.error("文件路径创建失败:"+result); } } file = null; log.info("获取到文件保存路径:"+result); return result; } }