Cov txheej txheem:

Cov ntaub ntawv pov thawj hauv Java yog dab tsi?
Cov ntaub ntawv pov thawj hauv Java yog dab tsi?

Video: Cov ntaub ntawv pov thawj hauv Java yog dab tsi?

Video: Cov ntaub ntawv pov thawj hauv Java yog dab tsi?
Video: Yog ntuj tsis pab ntshe kuv tuag lawm 8/6/2018 2024, Hlis ntuj nqeg
Anonim

khoom yog a ntaub ntawv extension rau cov ntaub ntawv feem ntau siv nyob rau hauv Java technologies muaj feem xyuam rau khaws cov configurable parameters ntawm ib daim ntawv thov. Txhua qhov ntsuas tau khaws cia ua ib khub ntawm cov hlua, ib qho khaws cia lub npe ntawm qhov ntsuas (hu ua tus yuam sij / daim ntawv qhia), thiab lwm qhov khaws cov nqi.

Ib yam li ib tug yuav nug, yuav ua li cas tsim cov ntaub ntawv hauv Java?

Yuav ua li cas los tsim config. Properties file:

  1. Qhib dab noj hnub. Txoj nyem rau ntawm qhov project, xaiv New → file → muab cov ntaub ntawv npe raws li "config. khoom” → Xaus. Peb tsis tuaj yeem sau java code hauv qhov no. Nws yog cov ntawv nyeem yooj yim.
  2. Sau cov ntsiab lus hauv qab no hauv cov ntaub ntawv cov khoom hauv qhov tseem ceeb: tus nqi khub hom:

Tsis tas li ntawd, qhov zoo ntawm cov ntaub ntawv yog dab tsi? Cov qhov zoo ntawm kev siv cov ntaub ntawv yog peb muaj peev xwm configure tej yam uas yog nquag hloov nyob rau hauv ib lub sij hawm ntawm lub sij hawm yam tsis tas yuav hloov dab tsi nyob rau hauv code. Cov ntaub ntawv muaj muab yooj yooj yim nyob rau hauv cov nqe lus ntawm configuration. Qauv cov ntaub ntawv yog qhia hauv qab no, uas muaj cov ntaub ntawv nyob rau hauv qhov tseem ceeb-tus nqi khub.

Kuj nug, dab tsi yog ib qho cuab yeej hauv Java?

Kev tshaj tawm. Cov khoom yog ib tug subclass ntawm Hashtable. Nws yog siv los tuav cov npe ntawm qhov tseem ceeb uas tus yuam sij yog ib txoj hlua thiab tus nqi kuj yog ib txoj hlua. Cov Cov khoom chav kawm yog siv los ntawm ntau lwm yam Java chav kawm. Piv txwv li, nws yog hom khoom xa rov qab los ntawm System.

Yuav ua li cas nyeem cov ntaub ntawv los ntawm cov ntaub ntawv hauv Java?

Test.java

  1. import java.util.*;
  2. import java.io.*;
  3. Public class Test {
  4. pej xeem static void main(String args)throws Exception{
  5. FileReader nyeem = tshiab FileReader("db.properties");
  6. Properties p=new Properties();
  7. p.load(nyeem ntawv);
  8. System.out.println(p.getProperty("user"));

Pom zoo: