74f6ee7f4307ddf68af299596b015f3073e81312.svn-base 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package com.sinosoft.common.util;
  2. import java.io.File;
  3. import java.io.IOException;
  4. import java.util.Properties;
  5. import org.apache.log4j.Logger;
  6. public class FilePathUtil {
  7. private static final Logger log = Logger.getLogger(FilePathUtil.class);
  8. /**
  9. * 根据不同操作系统获取不同文件上传或下载路径
  10. * @return String path
  11. * @throws IOException
  12. */
  13. public static String getUploadPath() throws IOException{
  14. String result = "";
  15. Properties props = new Properties();
  16. java.io.InputStream in = FilePathUtil.class
  17. .getResourceAsStream("../../../../fileupdown.properties");
  18. props.load(in);
  19. in.close();
  20. String winpath = props.getProperty("winpath");
  21. String linuxpath = props.getProperty("linuxpath");
  22. Properties sysprops = System.getProperties();
  23. String osName = sysprops.getProperty("os.name");
  24. if(osName.startsWith("win")||osName.startsWith("Win")){//windows系统
  25. result = winpath;
  26. //result = "D:\\upload\\aaa";
  27. }else if(osName.startsWith("linux")||osName.startsWith("Linux")){//linux系统
  28. result = linuxpath;
  29. }else{
  30. result = winpath;
  31. }
  32. File file = new File(result);
  33. if(!file.exists()){//文件夹不存在,则创建
  34. boolean flag = file.mkdirs();
  35. if(!flag){
  36. log.error("文件路径创建失败:"+result);
  37. }
  38. }
  39. file = null;
  40. log.info("获取到文件保存路径:"+result);
  41. return result;
  42. }
  43. }