|
|
Исходный текст программы
PropertyDemo.java
|
Оглавление |
Назад
// =======================================
// PropertyDemo.java
//
// (C) Alexandr Frolov, 1998
// E-mail: frolov@glasnet.ru
// Web: http://www.glasnet.ru/~frolov
// =======================================
import java.io.*;
import java.util.*;
public class PropertyDemo
{
static DataOutputStream os;
static DataInputStream is;
public static void main(String args[])
{
Properties prop = new Properties();
Properties prop1 = new Properties();
String szStr = "";
String szPhone = "";
byte bKbd[] = new byte[256];
StringTokenizer st;
prop.put("Ivanov", "322-223-228");
prop.put("Petrov", "326-211-227");
prop.put("Sidorov", "311-225-263");
prop.put("Ivanoff", "355-243-229");
Enumeration en = prop.keys();
System.out.println("\nProperties:\n");
while(en.hasMoreElements())
{
szStr = (String)en.nextElement();
szPhone = (String)prop.get(szStr);
System.out.println(szStr + ": "
+ szPhone);
}
try
{
os = new DataOutputStream(
new FileOutputStream("prop.txt"));
prop.save(os, "My properties");
os.close();
}
catch(Exception ex)
{
System.out.println(ex.toString());
}
try
{
is = new DataInputStream(
new FileInputStream("prop.txt"));
prop1.load(is);
is.close();
}
catch(Exception ex)
{
System.out.println(ex.toString());
}
System.out.println("\nLoaded properties:\n");
Enumeration en1 = prop1.keys();
while(en1.hasMoreElements())
{
szStr = (String)en1.nextElement();
szPhone = (String)prop1.get(szStr);
System.out.println(szStr + ": " +
szPhone);
}
}
}
Назад |
|
|