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)); }