package com.landtool.lanbase.test; import org.apache.commons.lang.StringUtils; import java.io.File; public class NcService { private static final String BASE_DIR = "/iserverData/NC/"; /** * * @param ncpath nc数据相对路径 * @param type 类型 * @param depth 深度 * @return */ public static String isNcDataFileExist(String ncpath, String type, String depth){ // String message = ""; // String cacheRelativePath = ncpath.substring(0,ncpath.indexOf(".")); // 文件路径 String filePath = BASE_DIR + "data/" + ncpath; // 缓存文件名称 String cacheName = cacheRelativePath + "_" + type + "_" + depth + ".dat" ; // 缓存文件相对路径 String relativePath = "cache/" + cacheName; // 缓存文件路径 String cachePath = BASE_DIR + "cache/" + cacheName; // 判断文件是否存在 File file = new File(cachePath); if (!file.exists()){ message = "{\"path\":\"error\"}"; }else{ message = "{\"path\":\"" + relativePath + "\"}"; } return message; } public static void main(String[] args) { try { String ncpath = "chinasea_201901_salt_1.dat"; String type = "type1"; String depth = "deep1"; String resultMessage = isNcDataFileExist(ncpath,type,depth); if (StringUtils.isNotEmpty(resultMessage)){ System.out.println(resultMessage); } }catch (Exception e){ e.printStackTrace(); } } }