1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
public class { public static void writeLog(String content) { try { SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); HttpSession session = WebContextFactory.get().getSession(); String operator = (String)session.getAttribute("userName"); String fileName = Init.getDir("log"); FileWriter writer = new FileWriter(fileName, true); writer.write(df.format(new Date()) + ' ' + operator + ' '+ content + "rn"); writer.close(); } catch (IOException e) { e.printStackTrace(); } } public static String readLog() throws IOException{ String fileName = Init.getDir("log"); File file=new File(fileName); if(!file.exists()||file.isDirectory()) throw new FileNotFoundException(); BufferedReader br=new BufferedReader(new FileReader(file)); String temp=null; StringBuffer sb=new StringBuffer(); temp=br.readLine(); while(temp!=null){ temp += "rn"; sb.insert(0, temp); temp=br.readLine(); } br.close(); return sb.toString(); } }
|
近期评论