写:
package com.wjy.write; import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter; public class FileWriter { public void writeContent(){
BufferedWriter bw=null;
try {
bw=new BufferedWriter(new OutputStreamWriter(new FileOutputStream("E:/svndemo/repository/conf/authzz")));
bw.write("xxx");
bw.close(); } catch (Exception e) {
// TODO: handle exception
} } }
读:
package com.wjy.read; import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader; public class FileReader {
public void readContent(){
String content=null;
BufferedReader br=null;
try {
br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("E:/svndemo/repository/conf/passwd"))));
while ((content=br.readLine())!=null) {
System.out.println(content);
}
br.close();
} catch (Exception e) {
// TODO: handle exception
} }
}
Main函数:
package com.wjy.main; import com.wjy.read.FileReader;
import com.wjy.write.FileWriter; public class MainOption {
public static void main(String args[]){
// TxtReader reader=new TxtReader();
// reader.readContent();
FileWriter writer=new FileWriter();
writer.writeContent();
}
}