private void getMapFileInMap(String folderPath, Map<Long, Object> map, String objectName) { try { File folder = new File(folderPath); File[] files = folder.listFiles(); for (File file : files) { if (!file.isDirectory()) { String[] fileName1 = file.getName().split("-"); String[] fileName2 = fileName1[1].split("\."); Object object = Class.forName(objectName).newInstance(); Method setIdMethod = object.getClass().getMethod("setId", Long.class); Method setTimeMethod = object.getClass().getMethod("setTime", Long.class); setIdMethod.invoke(object, Long.valueOf(fileName1[0])); setTimeMethod.invoke(object, Long.valueOf(fileName2[0])); map.put(Long.valueOf(fileName1[0]), object); } } } catch (Exception e) { e.printStackTrace(); } }

// Usage getMapFileInMap("D:/mapSycTrain/", allMapSycTrainMap, "MapSycTrain"); getMapFileInMap("D:/mapSycProject/", allMapSycProjectMap, "MapSycProject")

private final MapLong MapSycTrain allMapSycTrainMap = new HashMap; private final MapLong MapSycProject allMapSycProjectMap = new HashMap; 1加载本地文件到map private void getMapFileInMap try

原文地址: https://www.cveoy.top/t/topic/iM2x 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录