文件輸入的例子。

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;


public class iofiles {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args)  {
	
		FileOutputStream fos=null;
		try {
			File dir = new File("E:\\tempfile");
			if (!dir.exists()) {
				dir.mkdir();
			}
		 fos = new FileOutputStream("E:\\tempfile\\2.txt",true);
			String str = "guiling";
		/*	byte[] buf = str.getBytes();
			fos.write(buf);*/
			fos.write(str.getBytes());
			fos.close();
		} catch (Exception e) {
			System.out.println(e.toString()+"--");
		}
		finally{
			if(fos!=null){
			try {
				fos.close();
			} catch (IOException e) {
				
			throw new  RuntimeException(""+e);
			}
			}

	}

}
}

發佈了56 篇原創文章 · 獲贊 14 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章