You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.5 KiB
Java

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();
}
/**
* 获取xml文件的地址
*
* @return
*/
public static String getXmlDetailsPath() {
//获取目录结构
String path = FileUtils.currentPath();
return path + Codes.REQUEST_details_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);
}
}