中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

java屬性文件properties常用操作工具類

2018-07-20    來源:open-open

容器云強勢上線!快速搭建集群,上萬Linux鏡像隨意使用
對于java.util.Properties類,通常我們只需要做到以下3個學習目標:
1、認識properties文件,理解其含義,會正確創(chuàng)建properties文件。
2、會使用java.util.Properties類來操作properties文件。
3、掌握相對路徑,能正確書寫一個properties文件的相對路徑。
而在平時的工作中,會遇到各種各樣的需求,以下是一個封裝。
import java.io.File;  
import java.io.FileInputStream;  
import java.io.IOException;  
import java.io.InputStream;  
import java.util.Properties;  
  
/** 
 * properties 文件操作工具類 
 * @author Herman.Xiong 
 * @date 2015-1-29 下午04:27:19 
 * @version V3.0 
 * @since jdk 1.6,tomcat 6.0 
 */  
public class PropertiesUtil {  
    private static Properties prop = new Properties();   
    private static InputStream in;  
    private static final String path="src/com/herman/config/conf.properties";  
      
    /** 
     * 加載 
     */  
    static{  
        init();  
    }  
      
    /** 
     * 初始化 
     */  
    private static void init(){  
        try {  
            in=new FileInputStream(new File(path));  
            prop.load(in);  
        } catch (Exception e) {  
            e.printStackTrace();  
        }  
    }  
      
    /** 
     * 關閉InputStream 
     * @author Herman.Xiong 
     * @date 2015-1-30 上午09:41:04 
     */  
    private static void close(){  
        try {  
            if(null != in)  
                in.close();   
        } catch (Exception e) {  
            e.printStackTrace();  
        }  
    }  
      
    /** 
     * 重新加載Properties 
     * @author Herman.Xiong 
     * @date 2015-1-30 上午09:41:04 
     */  
    public static void reload(){  
        close();  
        prop.clear();//清除所有裝載的 鍵 - 值對  
        init();  
    }  
      
    /** 
     * 刪除所有鍵值 
     * @author Herman.Xiong 
     * @date 2015-1-30 上午09:42:04 
     */  
    public static void removeAll(){  
        close();  
        File file=new File(path);  
        if(file.exists())  
            file.delete();  
        try {  
            if(!file.exists())  
                new File(path).createNewFile();  
        } catch (IOException e) {  
            e.printStackTrace();  
        }  
    }  
      
    /** 
     * 輸出所有內(nèi)容到控制臺 
     * @author Herman.Xiong 
     * @date 2015-1-30 上午09:42:33 
     */  
    public static void outList(){  
        prop.list(System.out);  
    }  
      
    public static void main(String[] args) {  
        System.out.println(prop.getProperty("abc"));  
        outList();  
        reload();  
        outList();  
        removeAll();  
        System.out.println("重新加載.....");  
        outList();  
    }  
}  

標簽:

版權申明:本站文章部分自網(wǎng)絡,如有侵權,請聯(lián)系:west999com@outlook.com
特別注意:本站所有轉載文章言論不代表本站觀點!
本站所提供的圖片等素材,版權歸原作者所有,如需使用,請與原作者聯(lián)系。

上一篇:Android手機屏幕px轉dp和dp轉px工具類

下一篇:Python實現(xiàn)http文件下載