/** * 將資訊寫入到日誌 * @param content * @return * @throws IOException */public static boolean writeLog(String className,String ErrorInfo,String ErrorContent){String content=info(className, ErrorInfo, ErrorContent);File fileName = new File(System.getProperty("user.dir")+"/config/log.log");RandomAccessFile mm = null;boolean flag = false;FileOutputStream o = null;try {o = new FileOutputStream(fileName,true);o.write(content.getBytes("utf-8"));o.close();flag = true;} catch (IOException e) {e.printStackTrace();} finally {if (mm != null) {try {mm.close();} catch (IOException e) {e.printStackTrace();}}}return flag;} /** * * @param className 類名稱 * @param ErrorInfo 錯誤資訊 * @param ErrorContent 錯誤內容 * @return */public static String info(String className,String ErrorInfo,String ErrorContent){ StringBuffer buffer=new StringBuffer(); Date date = new Date(); SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String d = sd.format(date)+"\r\n"; buffer.append(d); buffer.append("錯誤類名為:").append(className).append("\r\n"); buffer.append("錯誤資訊為:").append(ErrorInfo).append("\r\n"); buffer.append("錯誤內容為:").append(ErrorContent).append("\r\n"); buffer.append("\r\n"); return buffer.toString();}