import java.io.*; import java.util.*; public class LoadPropertiesFromFile { public static void main(String[] args) { Properties prop = new Properties(); try { FileInputStream fis = new FileInputStream("config.properties"); prop.load(fis); } catch (IOException e) { e.printStackTrace(); } System.out.println(prop.getProperty("username")); } }
import java.io.*; import java.util.*; public class LoadPropertiesFromInputStream { public static void main(String[] args) { Properties prop = new Properties(); try { InputStream is = new ByteArrayInputStream("username=john\npassword=secret".getBytes()); prop.load(is); } catch (IOException e) { e.printStackTrace(); } System.out.println(prop.getProperty("password")); } }This code loads the properties from an input stream containing the properties in the format "key=value" and prints the value of the "password" property. The java.util package is part of the Java standard library, which means that it comes with the Java runtime environment and does not require any additional libraries or packages to be installed.