《JAVA相關文章索引(3)》__JAVA

來源:互聯網
上載者:User
1.基本常識

紀念我曾經的 JAVA 姿勢

Java核心技術點之泛型

eclipse怎麼用快速鍵定位到當前行的頭部或尾部

Java URL處理

清空map的方法

java抽象類別百度百科

如何取出ResultSet中的資料。


2.Java讀取設定檔


Java實現定時任務的三種方法

獲得執行jar的運行路徑-使用java.class.path 和 codesource的location

Java讀取Properties設定檔幾點注意事項

這段代碼有什麼用。

java中如何將string 轉化成long

實際生產情境下,之所以用到Properties是因為這樣可以把配置搞活,就自己用的,方案粘貼如下,首先在現有的project下建立一個package,就叫它util吧,該包下有這麼一類( PropertyUtil),類中實現代碼如下:

<span style="font-family:Microsoft YaHei;font-size:14px;">public class PropertyUtil {    private static Logger logger = Logger.getLogger(PropertyUtil.class);    private static String propFilePath = getCurrentJarPath() + "prop.properties";    public static Properties prop = null;    /**     * 讀取並載入設定檔     *      * @param ConfigFileName     *            設定檔地址     * @return     */    public static void loadConfig() {        try {            InputStream inputStream = new FileInputStream(new File(propFilePath));            prop = new Properties();            prop.load(inputStream);            // 擷取寫入列        } catch (Exception ex) {            logger.error(ex);        }    }    /**     * 擷取目前的目錄地址     *      * @return     */    public static String getCurrentJarPath() {        String c_path = PropertyUtil.class.getProtectionDomain().getCodeSource().getLocation().getPath();        String os_name = System.getProperty("os.name").toLowerCase();        c_path = os_name.startsWith("win") ? c_path.substring(1, c_path.lastIndexOf("/") + 1) : c_path.substring(0, c_path.lastIndexOf("/") + 1);        return c_path;    }</span>

要讀取的設定檔propertites,我是放在 src/main/resources(如果項目中沒有的話,可以以之為名建立一個source folder)中的,如下圖所示:


放在這個下面,通過maven install進行打包操作後,該設定檔在打好的project包的classes檔案下,實際要用到的時候,需要將引用的設定檔與執行jar包放到同級目錄下,那怎麼在主程式中引用設定檔呢。假設我要通過設定檔讀取的內容是某個ip值,如下圖所示:


主程式中首先需要匯入設定檔:

<span style="font-family:Microsoft YaHei;font-size:14px;">/** * 匯入設定檔路徑 */public ImportationData() {super();PropertyUtil.loadConfig();}</span>

具體引用操作為如下代碼:

<span style="font-family:Microsoft YaHei;font-size:14px;">PropertyUtil.prop.getProperty("kylinIp")</span>
如果需要引用其他內容,只需將括弧中的內容配置成你所設定的就可以了,特殊情況,在配置比如 long類型的定時時間時,預設通過以上方式讀取的時間是 string類型,如(1*1000*60),此時需要通過 Long.parseLong做個轉換。


3.Java擷取各種常用時間

Java擷取各種常用時間方法

java計算代碼執行時間

java 擷取程式執行時間


4.Java中的規範與重構

重構百度百科

Java包(package)的命名規範,java中package命名規則

JAVA命名規則

JAVA命名規範


5.Java中的Maven專案管理

XML注釋快速鍵


6.常見問題

java報錯Syntax error on token "return", invalid Type

(可以檢查一下是否將return語句放到了方法外面,就是類的最後一個括弧與方法最後一個括弧之間)


7.實戰演練

java實現多個檔案中資料去重問題並按升序排列

Java 讀取 txt文檔 存回二維數組

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.