Tabnine Logo
Properties
Code IndexAdd Tabnine to your IDE (free)

How to use
Properties
in
java.util

Best Java code snippets using java.util.Properties (Showing top 20 results out of 124,119)

Refine searchRefine arrow

  • FileInputStream
  • Enumeration
  • Vector
  • InputStream
  • Call
  • FileOutputStream
  • URL
  • InputStreamReader
  • BufferedInputStream
origin: libgdx/libgdx

private static Properties readPropertiesFromFile (File propertiesFile) throws IOException {
  InputStream stream = null;
  try {
    stream = new FileInputStream(propertiesFile);
    Properties properties = new Properties();
    properties.load(stream);
    return properties;
  } finally {
    if (stream != null) {
      try {
        stream.close();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }
}
 
origin: apache/geode

/**
 * Edits the specified property within the given property file
 *
 * @param filePath path to the property file
 * @param propertyName property name to edit
 * @param propertyValue new property value
 * @param append whether or not to append the given property value. If true appends the given
 *        property value the current value. If false, replaces the current property value with the
 *        given property value
 */
protected static void editPropertyFile(String filePath, String propertyName, String propertyValue,
  boolean append) throws Exception {
 FileInputStream input = new FileInputStream(filePath);
 Properties properties = new Properties();
 properties.load(input);
 String val;
 if (append) {
  val = properties.getProperty(propertyName) + propertyValue;
 } else {
  val = propertyValue;
 }
 properties.setProperty(propertyName, val);
 properties.store(new FileOutputStream(filePath), null);
 logger.info("Modified container Property file " + filePath);
}
origin: spring-projects/spring-framework

private static Properties createSampleProperties() {
  Properties properties = new Properties();
  properties.put("com.example.service.One", "service");
  properties.put("com.example.service.sub.Two", "service");
  properties.put("com.example.service.Three", "service");
  properties.put("com.example.domain.Four", "entity");
  return properties;
}
origin: square/okhttp

private static String versionString() {
 try {
  Properties prop = new Properties();
  InputStream in = Main.class.getResourceAsStream("/okcurl-version.properties");
  prop.load(in);
  in.close();
  return prop.getProperty("version");
 } catch (IOException e) {
  throw new AssertionError("Could not load okcurl-version.properties.");
 }
}
origin: stackoverflow.com

 Properties properties = new Properties();
try {
 properties.load(new FileInputStream("path/filename"));
} catch (IOException e) {
 ...
}
origin: spring-projects/spring-framework

@Override
public Properties convert(String source) {
  try {
    Properties props = new Properties();
    // Must use the ISO-8859-1 encoding because Properties.load(stream) expects it.
    props.load(new ByteArrayInputStream(source.getBytes(StandardCharsets.ISO_8859_1)));
    return props;
  }
  catch (Exception ex) {
    // Should never happen.
    throw new IllegalArgumentException("Failed to parse [" + source + "] into Properties", ex);
  }
}
origin: brianfrankcooper/YCSB

  System.exit(0);
 props.setProperty(Client.DB_PROPERTY, args[argindex]);
 argindex++;
} else if (args[argindex].compareTo("-P") == 0) {
 argindex++;
 Properties myfileprops = new Properties();
 try {
  myfileprops.load(new FileInputStream(propfile));
 } catch (IOException e) {
  System.out.println(e.getMessage());
 for (Enumeration e = myfileprops.propertyNames(); e.hasMoreElements();) {
  String prop = (String) e.nextElement();
  fileprops.setProperty(prop, myfileprops.getProperty(prop));
 props.put(name, value);
 argindex++;
} else if (args[argindex].compareTo("-table") == 0) {
  System.exit(0);
 props.put(CoreWorkload.TABLENAME_PROPERTY, args[argindex]);
origin: apache/incubator-dubbo

Properties properties = new Properties();
    FileInputStream input = new FileInputStream(fileName);
    try {
      properties.load(input);
    } finally {
      input.close();
  Enumeration<java.net.URL> urls = ClassHelper.getClassLoader().getResources(fileName);
  list = new ArrayList<java.net.URL>();
  while (urls.hasMoreElements()) {
    list.add(urls.nextElement());
    properties.load(ClassHelper.getClassLoader().getResourceAsStream(fileName));
  } catch (Throwable e) {
    logger.warn("Failed to load " + fileName + " file from " + fileName + "(ignore this file): " + e.getMessage(), e);
    Properties p = new Properties();
    InputStream input = url.openStream();
    if (input != null) {
      try {
        p.load(input);
        properties.putAll(p);
      } finally {
        try {
          input.close();
        } catch (Throwable t) {
origin: netty/netty

Properties props = new Properties();
try {
  Enumeration<URL> resources = classLoader.getResources("META-INF/io.netty.versions.properties");
  while (resources.hasMoreElements()) {
    URL url = resources.nextElement();
    InputStream in = url.openStream();
    try {
      props.load(in);
    } finally {
      try {
        in.close();
      } catch (Exception ignore) {
for (Object o: props.keySet()) {
  String k = (String) o;
  if (!props.containsKey(artifactId + PROP_VERSION) ||
    !props.containsKey(artifactId + PROP_BUILD_DATE) ||
    !props.containsKey(artifactId + PROP_COMMIT_DATE) ||
    !props.containsKey(artifactId + PROP_SHORT_COMMIT_HASH) ||
    !props.containsKey(artifactId + PROP_LONG_COMMIT_HASH) ||
    !props.containsKey(artifactId + PROP_REPO_STATUS)) {
    continue;
      new Version(
          artifactId,
          props.getProperty(artifactId + PROP_VERSION),
          parseIso8601(props.getProperty(artifactId + PROP_BUILD_DATE)),
          parseIso8601(props.getProperty(artifactId + PROP_COMMIT_DATE)),
origin: spring-projects/spring-framework

Properties entityReferences = new Properties();
    entityReferences.load(is);
    is.close();
Enumeration<?> keys = entityReferences.propertyNames();
while (keys.hasMoreElements()) {
  String key = (String) keys.nextElement();
  int referredChar = Integer.parseInt(key);
  Assert.isTrue((referredChar < 1000 || (referredChar >= 8000 && referredChar < 10000)),
      () -> "Invalid reference to special HTML entity: " + referredChar);
  int index = (referredChar < 1000 ? referredChar : referredChar - 7000);
  String reference = entityReferences.getProperty(key);
  this.characterToEntityReferenceMap[index] = REFERENCE_START + reference + REFERENCE_END;
  this.entityReferenceToCharacterMap.put(reference, (char) referredChar);
origin: stanfordnlp/CoreNLP

/**
 * This method reads in properties listed in a file in the format prop=value, one property per line.
 * Although {@code Properties.load(InputStream)} exists, I implemented this method to trim the lines,
 * something not implemented in the {@code load()} method.
 *
 * @param filename A properties file to read
 * @return The corresponding Properties object
 */
public static Properties propFileToProperties(String filename) {
 try {
  InputStream is = new BufferedInputStream(new FileInputStream(filename));
  Properties result = new Properties();
  result.load(is);
  // trim all values
  for (String propKey : result.stringPropertyNames()){
   String newVal = result.getProperty(propKey);
   result.setProperty(propKey,newVal.trim());
  }
  is.close();
  return result;
 } catch (IOException e) {
  throw new RuntimeIOException("propFileToProperties could not read properties file: " + filename, e);
 }
}
origin: alibaba/druid

private static void loadFilterConfig(Properties filterProperties, ClassLoader classLoader) throws IOException {
  if (classLoader == null) {
    return;
  }
  
  for (Enumeration<URL> e = classLoader.getResources("META-INF/druid-filter.properties"); e.hasMoreElements();) {
    URL url = e.nextElement();
    Properties property = new Properties();
    InputStream is = null;
    try {
      is = url.openStream();
      property.load(is);
    } finally {
      JdbcUtils.close(is);
    }
    filterProperties.putAll(property);
  }
}
origin: spring-projects/spring-framework

Properties props = new Properties();
while (urls.hasMoreElements()) {
  URL url = urls.nextElement();
  URLConnection con = url.openConnection();
  ResourceUtils.useCachesIfNecessary(con);
  InputStream is = con.getInputStream();
  try {
    if (resourceName.endsWith(XML_FILE_EXTENSION)) {
      props.loadFromXML(is);
      props.load(is);
    is.close();
origin: stackoverflow.com

 FileInputStream in = new FileInputStream("First.properties");
Properties props = new Properties();
props.load(in);
in.close();

FileOutputStream out = new FileOutputStream("First.properties");
props.setProperty("country", "america");
props.store(out, null);
out.close();
origin: spring-projects/spring-framework

/**
 * Copy the configured output {@link Properties}, if any, into the
 * {@link Transformer#setOutputProperty output property set} of the supplied
 * {@link Transformer}.
 * @param transformer the target transformer
 */
protected final void copyOutputProperties(Transformer transformer) {
  if (this.outputProperties != null) {
    Enumeration<?> en = this.outputProperties.propertyNames();
    while (en.hasMoreElements()) {
      String name = (String) en.nextElement();
      transformer.setOutputProperty(name, this.outputProperties.getProperty(name));
    }
  }
}
origin: jamesdbloom/mockserver

private static Properties readPropertyFile() {
  Properties properties = new Properties();
        properties.load(inputStream);
      } catch (IOException e) {
        e.printStackTrace();
        properties.load(new FileInputStream(propertyFile()));
      } catch (FileNotFoundException e) {
        if (MockServerLogger.MOCK_SERVER_LOGGER != null) {
  if (!properties.isEmpty()) {
    Enumeration<?> propertyNames = properties.propertyNames();
    while (propertyNames.hasMoreElements()) {
      String propertyName = String.valueOf(propertyNames.nextElement());
      propertiesLogDump.append("\t").append(propertyName).append(" = ").append(properties.getProperty(propertyName)).append(NEW_LINE);
origin: cbeust/testng

@DataProvider(name = "provider")
public Object[][] createData() throws FileNotFoundException, IOException {
 Properties p = new Properties();
 List<Object> vResult = new ArrayList<>();
 p.load(new FileInputStream(new File("c:/t/data.properties")));
 for (Enumeration e = p.keys(); e.hasMoreElements(); ) {
  vResult.add(e.nextElement());
 }
 Object[][] result = new Object[vResult.size()][1];
 for (int i = 0; i < result.length; i++) {
  result[i] = new Object[] { vResult.get(i) };
 }
 return result;
}
origin: GitLqr/LQRWeChat

/**
 * 把字符串键值对的map写入文件
 */
public static void writeMap(String filePath, Map<String, String> map,
              boolean append, String comment) {
  if (map == null || map.size() == 0 || StringUtils.isEmpty(filePath)) {
    return;
  }
  FileInputStream fis = null;
  FileOutputStream fos = null;
  File f = new File(filePath);
  try {
    if (!f.exists() || !f.isFile()) {
      f.createNewFile();
    }
    Properties p = new Properties();
    if (append) {
      fis = new FileInputStream(f);
      p.load(fis);// 先读取文件,再把键值对追加到后面
    }
    p.putAll(map);
    fos = new FileOutputStream(f);
    p.store(fos, comment);
  } catch (Exception e) {
    LogUtils.e(e);
  } finally {
    IOUtils.close(fis);
    IOUtils.close(fos);
  }
}
origin: stanfordnlp/CoreNLP

public static void main(String[] args) throws Exception {
 Properties props = StringUtils.argsToProperties(args);
 StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
 String file = props.getProperty("file");
 String loadFile = props.getProperty("loadFile");
 if (loadFile != null && ! loadFile.isEmpty()) {
  CustomAnnotationSerializer ser = new CustomAnnotationSerializer(false, false);
  InputStream is = new FileInputStream(loadFile);
  Pair<Annotation, InputStream> pair = ser.read(is);
  pair.second.close();
  Annotation anno = pair.first;
  System.out.println(anno.toShorterString(StringUtils.EMPTY_STRING_ARRAY));
  is.close();
 } else if (file != null && ! file.equals("")) {
  String text = edu.stanford.nlp.io.IOUtils.slurpFile(file);
  Annotation doc = new Annotation(text);
  pipeline.annotate(doc);
  CustomAnnotationSerializer ser = new CustomAnnotationSerializer(false, false);
  PrintStream os = new PrintStream(new FileOutputStream(file + ".ser"));
  ser.write(doc, os).close();
  log.info("Serialized annotation saved in " + file + ".ser");
 } else {
  log.info("usage: CustomAnnotationSerializer [-file file] [-loadFile file]");
 }
}
origin: apache/geode

/**
 * Populate the available server public keys into a local static HashMap. This method is not
 * thread safe.
 */
public static void initCertsMap(Properties props) throws Exception {
 certificateMap = new HashMap();
 certificateFilePath = props.getProperty(PUBLIC_KEY_FILE_PROP);
 if (certificateFilePath != null && certificateFilePath.length() > 0) {
  KeyStore ks = KeyStore.getInstance("JKS");
  String keyStorePass = props.getProperty(PUBLIC_KEY_PASSWD_PROP);
  char[] passPhrase = (keyStorePass != null ? keyStorePass.toCharArray() : null);
  FileInputStream keystorefile = new FileInputStream(certificateFilePath);
  try {
   ks.load(keystorefile, passPhrase);
  } finally {
   keystorefile.close();
  }
  Enumeration aliases = ks.aliases();
  while (aliases.hasMoreElements()) {
   String alias = (String) aliases.nextElement();
   Certificate cert = ks.getCertificate(alias);
   if (cert instanceof X509Certificate) {
    String subject = ((X509Certificate) cert).getSubjectDN().getName();
    certificateMap.put(subject, cert);
   }
  }
 }
}
java.utilProperties

Javadoc

A Properties object is a Hashtable where the keys and values must be Strings. Each property can have a default Properties list which specifies the default values to be used when a given key is not found in this Propertiesinstance.

Character Encoding

Note that in some cases Properties uses ISO-8859-1 instead of UTF-8. ISO-8859-1 is only capable of representing a tiny subset of Unicode. Use either the loadFromXML/ storeToXML methods (which use UTF-8 by default) or the load/ store overloads that take an OutputStreamWriter (so you can supply a UTF-8 instance) instead.

Most used methods

  • <init>
  • getProperty
    Searches for the property with the specified name. If the property is not found, it looks in the def
  • load
    Loads properties from the specified Reader. The properties file is interpreted according to the foll
  • setProperty
    Maps the specified key to the specified value. If the key already exists, the old value is replaced.
  • put
  • get
  • entrySet
  • putAll
  • containsKey
  • store
    Stores the mappings in this Properties object to out, putting the specified comment at the beginning
  • keySet
  • stringPropertyNames
    Returns a set of keys in this property list where the key and its corresponding value are strings, i
  • keySet,
  • stringPropertyNames,
  • remove,
  • propertyNames,
  • size,
  • isEmpty,
  • keys,
  • clear,
  • clone,
  • toString

Popular in Java

  • Running tasks concurrently on multiple threads
  • getResourceAsStream (ClassLoader)
  • setScale (BigDecimal)
  • getApplicationContext (Context)
  • ServerSocket (java.net)
    This class represents a server-side socket that waits for incoming client connections. A ServerSocke
  • MessageDigest (java.security)
    Uses a one-way hash function to turn an arbitrary number of bytes into a fixed-length byte sequence.
  • NoSuchElementException (java.util)
    Thrown when trying to retrieve an element past the end of an Enumeration or Iterator.
  • JTextField (javax.swing)
  • DateTimeFormat (org.joda.time.format)
    Factory that creates instances of DateTimeFormatter from patterns and styles. Datetime formatting i
  • SAXParseException (org.xml.sax)
    Encapsulate an XML parse error or warning.> This module, both source code and documentation, is in t
  • Top plugins for Android Studio
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now