import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
public class TestException {
public static void main(String [] arge) throws NewException, IOException{
/*
int aa=0;
if(aa==0)
throw new NewException("抛出新的异常");
else
System.out.print("nimenhao");
*/
Properties pr = new Properties();
for(int i=0;i<10;i++)
pr.setProperty(""+i, "a"+i);
File str = new File("d:/prop1.properties");
FileOutputStream fo = new FileOutputStream(str);
pr.storeToXML(fo, "properties");
fo.close();
try {
FileInputStream fi = new FileInputStream(str);
pr.load(fi);
fi.close();
for(int i=0;i<10;i++)
System.out.println(pr.getProperty(""+i));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
properties 读取和写入配置文件
最新推荐文章于 2023-06-29 14:39:34 发布