자바 바이트 흐름 출력 흐름 FileOutputStream 및 흐름 이상 처리

홈 페이지 API:
https://docs.oracle.com/javase/8/docs/api/org/omg/CORBA/portable/OutputStream.html

	/**
	 * OutputStream:   ,        ,    
	 * 	write(int b)       
	 * 	write(byte[] b)        
	 * 	write(byte[] b,int,int),      ,int,    ,int,      
	 * 	fulsh();          ,               ,           
	 * 	close();   ,                  ,           
	 * 	
	 *    :FileOutputStream,                   
	 *     
	 * FileOutputStream("D:\\a.txt");
	 * FileOutputStream(File file);
	 * FileOutputStream("D:\\a.txt",true);true:            
	 * FileOutputStream(File file,true);true:            
	 */
	public static void main(String[] args) throws IOException {
		//writeFile();
		//keepWriteFile();
		getException();
	}
	/**
	 *       
	 * 	             ,         ,                   ,U        ....
	 */
	private static void getException() {
		FileOutputStream fos = null;//       
		try {
			//                ,    catch,    close()  try       ,  finally             
			fos = new FileOutputStream("D:\\a.txt");
			fos.write("Hello".getBytes());
		} catch (IOException e) {
			throw new RuntimeException("      !     :
"+e.getMessage()); }finally{ try { if(fos != null)// fos.close(); } catch (IOException e) { throw new RuntimeException(" ! :
"+e.getMessage()); } } } /** * * FileOutputStream(File file,true) FileOutputStream("D:\\a.txt",true); * \r
*/ private static void keepWriteFile() throws IOException { File file = new File("D:\\a.txt"); FileOutputStream fos = new FileOutputStream(file,true);// true, false fos.write("Hello".getBytes()); fos.write("\r
World".getBytes()); fos.close(); System.out.println(" "); } /** * */ private static void writeFile() throws IOException { // , , , FileOutputStream fos = new FileOutputStream("D:\\a.txt"); // // fos.write(100);// d, ASCLL // 100 ASCLL /* * fos.write(49); fos.write(48); fos.write(48); */ // byte byte[] b = { 65, 66, 67, 68, }; // fos.write(b); // fos.write(b,1,2); // fos.write("Hello".getBytes()); fos.close(); System.out.println(" "); }

좋은 웹페이지 즐겨찾기