BufferedReader和BufferedOutputStream之间的灵活应用【回钦波】
package log;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.util.Properties;
public class ReadProperties {
?static BufferedReader br = null;
?static FileReader fr = null;
?
?public static void main(String args[]){
??
??try {
???br = new BufferedReader(new FileReader("log.properties"));??//这里最好用? ./log.properties
???
??} catch (FileNotFoundException e) {
???// TODO Auto-generated catch block
???e.printStackTrace();
??}
?
?
??Properties properties = new Properties();
??try {
???properties.load(br);
???String file_path=properties.getProperty("log_path");
???System.out.println(file_path);
???
???
??//?BufferedOutputStream bo = new BufferedOutputStream(new FileOutputStream(file_path));
?
????? PrintStream bo = new PrintStream(new FileOutputStream(file_path),true);?? //printStream可以用println方?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? //法来输出字符串
????? bo.println("welcome come to huiqinbo.com");
??} catch (IOException e) {
???// TODO Auto-generated catch block
???e.printStackTrace();
??}
//??
//??return true;
?}
?
}
?
?
?
?
1. //配置文件放在了项目的根目录底下
??? log.properties
?
??? log_path?? = .\\log1.txt
?
?
2.在项目底下的log1.txt文件中查看内容:
?? welcome come to huiqinbo.com
?
?
?
?
?
?
?
?
?