复制代码代码如下:
импортировать java.io.*;
импортировать java.text.simpledateformat;
Импорт java.util.*;
импортировать java.util.logging.logger;
Общественный класс Andylogger
{
// дефолтный корневой путь установки SSLVPN
частная статическая строка rootpath = "c: // temp2";
// переменная для создания новой линии
частная конечная статическая строка enter = System.getProperty ("line.separator");
Private Static SimpleDateFormat SDF =
new SimpleDateFormat ("yyyy-mm-dd HH: MM: SS");
Общественный статический синхронизированный журнал void (String FileName, String LogMessage)
{
пытаться
{
File folder = new File (rootPath);
if (! folder.exists ())
{
folder.mkdir ();
}
File file = новый файл (rootpath + "//" + filename + ".log");
if (! file.exists ())
{
file.createnewfile ();
}
BufferedReader in = new BufferedReader (новый FileReader (файл));
String str = "";
String strtoAl = "";
while ((str = in.readline ())! = null)
{
strtoAl + = (str + enter);
}
strtoAl = strtoAl + (sdf.format (new date ()) + "" + logmessage + enter);
in.close ();
BufferedWriter Out = new BufferedWriter (New FileWriter (файл));
out.write (strtoal);
out.close ();
}
Поймать (исключение E)
{
e.printstacktrace ();
}
}
Общественный статический синхронизированный журнал void (String FileName, String [] LogMessages)
{
пытаться
{
File folder = new File (rootPath);
if (! folder.exists ())
{
folder.mkdir ();
}
File file = новый файл (rootpath + "//" + filename + ".log");
if (! file.exists ())
{
file.createnewfile ();
}
BufferedReader in = new BufferedReader (новый FileReader (файл));
String str = "";
String strtoAl = "";
while ((str = in.readline ())! = null)
{
strtoAl + = (str + enter);
}
для (int i = 0; i <logmessages.length; i ++)
{
String logmessage = logmessages [i];
strtoAl = strtoAl + (sdf.format (new date ()) + "" + logmessage + enter);
}
in.close ();
BufferedWriter Out = new BufferedWriter (New FileWriter (файл));
out.write (strtoal);
out.close ();
}
Поймать (исключение E)
{
e.printstacktrace ();
}
}
Public Static Void Main (String Args [])
{
Andylogger.log ("bug223", "timeisjjja");
String [] logMessages = {"111", "222", "333"};
Andylogger.log ("bug223", logmessages);
}
}