java Properties (属性集)

 加载Properties

Properties downloadLog = new Properties();
try {
                   //加载logFile文件
            downloadLog.load(new FileReader(logFile));
        } catch (IOException e) {
            e.printStackTrace();
        }

 设置和读取属性

final String uri = httpServletRequest.getRequestURI();
String property = downloadLog.getProperty(uri); if (property == null) { downloadLog.setProperty(uri, "1"); } else { int count = 0; try { count = Integer.parseInt(property); } catch (NumberFormatException e) { // silent } count++; downloadLog.setProperty(uri, Integer.toString(count)); }

 

posted @ 2019-04-16 13:17  江期玉  阅读(129)  评论(0编辑  收藏  举报