Verenga Zvivakwa Faira muJava Iine ResourceBundle

Kune nzira dzinoverengeka dzekutakudza nekuverenga zvivakwa faira kubva kuJava, asi iri nyore uye yakatwasuka iri kushandisa iyo ResourceBundle kirasi.

Kutanga, iwe unofanirwa kugadzira faira rezvivakwa pasi pezviwanikwa dura. Mune yakajairwa Maven chirongwa, izvi zvinoita kunge zvinotevera

Mumuenzaniso uyu, iyo zvivakwa faira inonzi config.properties

Izvo zvemukati mezvivakwa faira zviri muchimiro chezita = kukosha

Muenzaniso:

browser=chrome

Inoenderana:

Mukirasi yeJava, tinogona kushandisa iyo ResourceBundle kirasi kuverenga kubva kune zvivakwa faira:

public class ReadPropertiesFile {
private static ResourceBundle rb = ResourceBundle.getBundle('config');
public static void main(String[] args) {
String browser = rb.getString('browser');
System.out.println(browser);
} }

Kubuda:

chrome