Java traversal guide to the properties file

  • 2020-04-01 01:10:44
  • OfStack

In Java project development, it is essential to use the properties file as the configuration. Many system configuration information, file upload configuration information, and so on are saved in this way.
Learning to manipulate the properties file is also a Java foundation.

 
public class PropertiesUtil { 
public static Map getFileIO(String fileName){ 
Properties prop = new Properties(); 
Map propMap=new HashMap(); 
InputStream in = PropertiesUtil.class.getResourceAsStream(fileName); 
try { 
prop.load(in); 
Setkeyset = prop.keySet(); 
for (Object object : keyset) { 
String propValue= prop.getProperty(object.toString()).toString(); 
propMap.put(object.toString(), prop.getProperty(object.toString()).toString()); 
System.out.println(object.toString()+" : "+propValue); 
} 
} catch (IOException e) { 
e.printStackTrace(); 
}finally{ 
try { 
in.close(); 
} catch (IOException e) { 
e.printStackTrace(); 
} 
} 
return null; 
} 
public static void main(String[] args) { 
getFileIO("/loginurl.properties"); 
} 
} 


Related articles: