?? fileappender.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 + -