【FileOutputStream類:write用法】
阿新 • • 發佈:2018-11-09
package test; import java.io.FileOutputStream; import java.io.IOException; /** * @author shusheng * @description * @Email [email protected] * @date 2018/11/9 14:50 */ public class FileOutputStreamDemo2 { public static void main(String[] args) throws IOException { /** *位元組輸出流操作步驟: *A:建立位元組輸出流物件 *B:呼叫write()方法 *C:釋放資源 * *public void write(int b):寫一個位元組 *public void write(byte[] b):寫一個位元組陣列 *public void write(byte[] b,int off,int len):寫一個位元組陣列的一部分*/ FileOutputStream fos = new FileOutputStream("fos.txt"); byte[] bys = {97,98,99,100,101}; fos.write('1'); fos.write(bys); fos.write(bys, 0, 2); fos.close(); } }