Java Properties.load(InputStream inStream)
Syntax
Properties.load(InputStream inStream) has the following syntax.
public void load(InputStream inStream) throws IOException
Example
In the following code shows how to use Properties.load(InputStream inStream) method.
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Properties;
/* w ww .j a v a2s. c o m*/
public class Main {
public static void main(String[] args) throws Exception {
Properties prop = new Properties();
String s = "Chapter Count=200";
String s2 = "Tutorial Count=15";
// create a new input and output stream
FileOutputStream fos = new FileOutputStream("properties.txt");
FileInputStream fis = new FileInputStream("properties.txt");
// write the first property in the output stream file
fos.write(s.getBytes());
// change the line between the two properties
fos.write("\n".getBytes());
// write next property
fos.write(s2.getBytes());
// load from input stream
prop.load(fis);
// print the properties list from System.out
prop.list(System.out);
}
}
The code above generates the following result.
Home »
Java Tutorial »
java.util »
Java Tutorial »
java.util »