获取本地文件

constants配置文件

static_host=http://192.168.0.2:8070
music_path=/upload/
获取constants数据

public class Constants {

	private static Logger logger=Logger.getLogger(Constants.class);
	public static  String ARTICLE_IMAGE_MAX_HEIGHT="article_image_max_height";
	public static  String ARTICLE_IMAGE_MAX_WIDTH="article_image_max_width";
	public static  String DOCTOR_HEAD_MAX_HEIGHT="doctor_head_max_height";
	public static  String DOCTOR_HEAD_MAX_WIDTH="doctor_head_max_width";
	public static  String CUSTOMER_HEAD_MAX_HEIGHT="customer_head_max_height";
	public static  String CUSTOMER_HEAD_MAX_WIDTH="customer_head_max_width";
	public static String ARTICLE_FOCUS_IMAGE_MAX_HEIGHT="article_focus_image_max_height";
	public static String ARTICLE_FOCUS_IMAGE_MAX_WIDTH="article_focus_image_max_width";
	public static  String IMG_PATH="img_path";
	public static  String FILE_PATH="file_path";
	public static  String MUSIC_PATH="music_path";
	public static  String LUCENE_PATH="lucene_path";
	public static  String STATIC_HOST="static_host";
	public static  String IMG_MAX_SIZE="img_max_size";
	public static  String IMG_EXT="img_ext";
	public static  String MEDIA_MAX_SIZE="media_max_size";
	public static  String MEDIA_EXT="media_ext";
	public static  String FILE_MAX_SIZE="file_max_size";
	public static  String FILE_EXT="file_ext";
	private static String fullFilePath;
	private static String fullImagePath;
	private static String fullMusicPath;
	public static String DIET_CALORIE_IMAGE_MAX_HEIGHT="diet_calorie_image_max_height";
	public static String DIET_CALORIE_IMAGE_MAX_WIDTH="diet_calorie_image_max_width";
	
	public static String LUNTAN_IMAGE_MAX_HEIGHT="luntan_image_max_height";
	public static String LUNTAN_IMAGE_MAX_WIDTH="luntan_image_max_width";
	
	private static Properties props;
	static {
		refresh();
	}

	public static void refresh() {
		props = new Properties();
		try {
			props.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("config/constants.properties"));
			fullFilePath=null;
			fullImagePath=null;
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static String getValue(String key) {
		return props.getProperty(key);
	}
	
	public static String getFullImagePath(){
		if (fullImagePath==null) {
			fullImagePath= new StringBuilder().append(Constants.getValue(Constants.STATIC_HOST))
					.append(Constants.getValue(Constants.IMG_PATH)).toString();
		}
		return fullImagePath;
	}
	public static String getFullFilePath(){
		if (fullFilePath==null) {
			fullFilePath=new StringBuilder().append(Constants.getValue(Constants.STATIC_HOST))
					.append(Constants.getValue(Constants.FILE_PATH)).toString();
		}
		return fullFilePath;
	}
	
	public static String getFullMusicPath(){
		if (fullMusicPath==null) {
			fullMusicPath=new StringBuilder().append(Constants.getValue(Constants.STATIC_HOST))
					.append(Constants.getValue(Constants.MUSIC_PATH)).toString();
		}
		return fullMusicPath;
	}
	
	public static void main(String[] args){
		System.out.println("STATIC_HOST:"+getValue(STATIC_HOST));
		System.out.println("STATIC_HOST:"+new StringBuilder().append(Constants.getValue(Constants.STATIC_HOST)).append(Constants.getValue(Constants.IMG_PATH)).toString());
		System.out.println("STATIC_HOST:"+new StringBuilder().append(Constants.getValue(Constants.STATIC_HOST)).append(Constants.getValue(Constants.FILE_PATH)).toString());
		System.out.println("STATIC_HOST:"+new StringBuilder().append(Constants.getValue(Constants.STATIC_HOST)).append(Constants.getValue(Constants.MUSIC_PATH)).toString());
	}
	
}

拼接路径

map.put("url", Constants.getFullMusicPath()+music.getUrl());




阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/tiankongdefengling/article/details/79956652
个人分类: day day up
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭