package com.docus.bgts.utils; import com.alibaba.fastjson.JSON; import com.docus.bgts.enums.Codes; import java.io.File; import java.io.IOException; import java.util.Map; public class FileUtils { /** * 获取jar包所在位置 * * @return */ public static String currentPath() { File dir = new File("."); String currentpath = ""; try { currentpath = dir.getCanonicalPath(); } catch (IOException e) { e.printStackTrace(); } return currentpath; } /** * 获取xml文件的地址 * * @return */ public static String getXmlPath() { //获取目录结构 String path = FileUtils.currentPath(); return path + Codes.REQUEST_XML.getMessage(); } /** * 获取静态文件中的内容 * * @param name * @return */ public static Object getJsonByName(String name) { //获取目录结构 String path = FileUtils.currentPath(); //解析json映射文件 String json = JsonUtils.readJsonFile(path + Codes.JSON_ADDRESS.getMessage()); Map jsonMap = JSON.parseObject(json, Map.class); return jsonMap.get(name); } }