读文件
一,
String proppath = "/org/b/pool/";
String propname = "db.properties";
URL propertyurl = getClass().getResource(
proppath + propname);
Properties dbProps = new Properties();
try {
FileInputStream in = new FileInputStream(propertyurl.getPath());
dbProps.load(in);
} catch (Exception e) {
System.err.println("不能读取属性文件. " +
"请确保db.properties在CLASSPATH指定的路径中");
return;
}
二,
String str;
String rdfile;
BufferedReader br;
br = new BufferedReader(new FileReader(rdfile));
while ( (str = br.readLine()) != null) {
//
}
写文件
一,
String wrfile;
FileWriter out = new FileWriter(new File(wrfile));
out.write("\r\n");
out.close();
二,
FileOutputStream output = null;
PrintStream out = null;
try {
output = new FileOutputStream("test.txt", false);
output.flush();
out = new PrintStream(output,false,"UTF8");
out.println(str);
out.println("所有");
out.println("程序");