java.se.io.2輸出流

package com.knock.io;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

import org.junit.Test;

/**
 * @date 160802am
 * 測試怎麼把東西寫到文件
 * */
public class KbOutput {
	@Test
	public void test(){
		OutputStream os =null;
		try {
			os = new FileOutputStream("E:/test/a.txt",true);//os = new FileOutputStream("E:/test/a.txt");
			String str = "i m shadow u r light\n";
			byte[] arr = str.getBytes(); 
			os.write(arr);
			os.flush();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			try {
				if(null!=os){
					os.close();
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章