:D 这个是07年,可能是在8月份写的。。。大约在夏季。。。
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Enumeration;
import java.util.InvalidPropertiesFormatException;
import java.util.Iterator;
import java.util.Properties;
import java.util.Set;
public class RWProperties ...{
public RWProperties() ...{
// TODO Auto-generated constructor stub
}
//读属性文件
private static Properties readProperties()...{
Properties prop = new Properties();
FileInputStream finps = null;
try ...{
finps = new FileInputStream("g:\DB.properties");
prop.load(finps);
} catch (Exception e) ...{
// TODO Auto-generated catch block
e.printStackTrace();
}finally ...{
try ...{
finps.close();
} catch (IOException e) ...{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return prop;
// prop.list(System.out);
}
private static void writerProperties()...{
FileOutputStream fouts = null;
Properties prop = new Properties(RWProperties.readProperties());//在原属性文件上追加记录
Properties prop = new Properties();//写新的属性文件
prop.setProperty("dsssssssssssss0","caaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
prop.setProperty("url","jdbc:sqlserver://localhost:1433;databasename=pubs");
prop.setProperty("user","sa");
prop.setProperty("pwd","sa");
try ...{
fouts = new FileOutputStream("g:\DB.properties");
prop.store(fouts, "DB");
} catch (IOException e) ...{
// TODO Auto-generated catch block
e.printStackTrace();
}finally ...{
try ...{
fouts.close();
} catch (IOException e) ...{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
//生成XML格式的属性文件
private static void writerPropertiesXml()...{
FileOutputStream fouts = null;
Properties prop = new Properties();
prop.setProperty("driver0","com.microsoft.jdbc.sqlserver.SQLServerDriver");
prop.setProperty("driver1","sun.jdbc.odbc.JdbcOdbcDriver");
prop.setProperty("driver","com.microsoft.sqlserver.jdbc.SQLServerDriver");
prop.setProperty("url0","jdbc:microsoft:sqlserver://localhost:1433;databasename=PersonnelManagement");
prop.setProperty("url1","jdbc:odbc:PersonnelManagement");
prop.setProperty("url","jdbc:sqlserver://localhost:1433;databasename=pubs");
prop.setProperty("user","sa");
prop.setProperty("pwd","sa");
try ...{
fouts = new FileOutputStream("g:\DB.xml");
prop.storeToXML(fouts, "DB");
} catch (IOException e) ...{
// TODO Auto-generated catch block
e.printStackTrace();
}finally ...{
try ...{
fouts.close();
} catch (IOException e) ...{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public static void main(String[] args)...{
// RWProperties.readProperties();
RWProperties.writerProperties();
// RWProperties.writerPropertiesXml();
}
}