package IO流;
import java.io.*;
public class TestOutputStream {
public static void main(String[] args) throws IOException {
File file=new File("d:"+File.separator+"demo"+File.separator+"mldn.txt");
//判斷目錄存在與否
if (!file.getParentFile().exists()){
file.getParentFile().mkdirs();
}
//使用fileOuputStream和其子類進行對象執行個體化
OutputStream output=new FileOutputStream(file);
String str="lwq在技術的路上一路向前";
byte data[]=str.getBytes();
//輸出全部位元組數組
// output.write(data);
//輸出單個位元組
// for (int x=0;x<data.length;x++){
// output.write(data[x]);
// }
//輸出部分位元組數組内容
output.write(data,6,6);
output.close();
}
}
位元組輸出流——OutputStream,是一個抽象類如果要進行檔案操作,就需要一個子類FileOutputStream類來完成操作。常用的方法有:
(1)public abstract void write( int b);輸出單個位元組。
(2)public void write(byte[] b);輸出全部位元組數組資料
(3)public void write(byte[] b,int off,int len);輸出部分位元組數組資料。