In the development process, the use of the properties file as the configuration is basically essential, many such as system configuration information, File Upload configuration information, and so on are saved in this way.
Learning to operate the properties file is also the basis of java.
/**
* @ Copyright 2012
* All right reserved
* @ Version Creation Time: Created on Oct 31,201 2
* @ Author: Create by www.360buyli.com
* @ Email: 360buyli@gmail.com
* @ Description how to read and traverse properties files in java
*/
Public class PropertiesUtil {
Public static Map <String, String> getFileIO (String fileName ){
Properties prop = new Properties ();
Map <String, String> propMap = new HashMap <String, String> ();
InputStream in = PropertiesUtil. class. getResourceAsStream (fileName );
Try {
Prop. load (in );
Set <Object> keyset = 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 ();
} Www.2cto.com
}
Return null;
}
Public static void main (String [] args ){
GetFileIO ("/loginurl. properties ");
}
}