import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
public class FileOption {
public static void fileWrite(){
System.out.println("fileWrite");
try {
FileWriter out = new FileWriter("d:/tempTest/fileWrite.html");
out.write("foo!");
out.close();
}catch(Exception e){
System.out.println(e.toString());
}
}
public static void bufferedFileOutputSteam(){
System.out.println("bufferedFileOutputSteam");
try{
FileOutputStream out = new FileOutputStream(new File("d:/tempTest/bufferedFileOutputSteam.html"));
BufferedOutputStream bufOut = new BufferedOutputStream(out);
out.write("foo!".getBytes());
bufOut.flush();
bufOut.close();
}catch(Exception e){
System.out.println(e.toString());
}
}
public static void fileOutputSteam(){
System.out.println("fileOutputSteam");
try{
FileOutputStream out = new FileOutputStream(new File("d:/tempTest/fileOutputSteam.html"));
out.write("foo!".getBytes());
out.close();
}catch(Exception e){
System.out.println(e.toString());
}
}
//其中执行效率高到低依次为:fileWrite()>bufferedFileOutputSteam()>fileOutputSteam()
public static void main(String []args){
FileOption.fileWrite();
FileOption.fileOutputSteam();
FileOption.bufferedFileOutputSteam();
}
}