⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fileappender.java

📁 JAVA实现的一个类库
💻 JAVA
字号:
package cn.edu.nju.software.sd.cll;import java.io.File;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.PrintWriter;// </editor-fold> /** * class FileAppender,as the class Console,impements the interface Appender * Dealing with the file input. */public class FileAppender implements Appender {    // <editor-fold defaultstate="collapsed" desc=" UML Marker ">     // #[regen=yes,id=DCE.D45FAE28-B82C-109D-6194-281E3232603B]    // </editor-fold>     private String Destination;    // @SuppressWarnings("unused")	//private String name;    // <editor-fold defaultstate="collapsed" desc=" UML Marker ">     // #[regen=yes,id=DCE.8E27525E-6014-0660-AD54-D9FD9A591E4D]    // </editor-fold>     private Layout layout; // public FileAppender(String name,Layout layout, String Destination){//		this.name=name;//		this.layout=layout;//		this.Destination=Destination;//	}    /**     * Default construct.     */          public FileAppender(Layout layout, String substring) {	// TODO Auto-generated c     		this.layout=layout;       		this.Destination=substring;       }          /**           * setLayout method.to hidden the private ins'layout'           */		public void setLayout(Layout layout)  {                    this.layout=layout;        }                    /**           * doLog,the real function to deal with the 'update' in the observer pattern.           * @param message           * @param logger           */public void doLog(String message,Logger logger){	PrintWriter outputStream=null;		try {			outputStream=new PrintWriter(new FileOutputStream(Destination,true));					} catch (FileNotFoundException e) {			System.out.println("Open file failed:  "+Destination);			int i=Destination.lastIndexOf("/");						File file=new File(Destination.substring(0,i));			file.mkdirs();		}		outputStream.println(this.layout.format(message, logger));		outputStream.close();	} /** * realize of the method in the interface 'Appender'  */    public void update(Logger logger,String message) {                 doLog(message,logger);    }    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -