Copy Code code as follows:
Import java.io.*;
Import Java.text.SimpleDateFormat;
Import java.util.*;
Import Java.util.logging.Logger;
public class Andylogger
{
The defaulted root path of SSLVPN installation
private static String RootPath = "C:\\TEMP2";
Variable for creating new line
Private final static String enter = System.getproperty ("Line.separator");
private static SimpleDateFormat SDF =
New SimpleDateFormat ("Yyyy-mm-dd hh:mm:ss");
public static synchronized void log (string fileName, String logmessage)
{
Try
{
File Folder = new file (RootPath);
if (!folder.exists ())
{
Folder.mkdir ();
}
File File = new file (RootPath + "\" + fileName + ". Log");
if (!file.exists ())
{
File.createnewfile ();
}
BufferedReader in = new BufferedReader (new FileReader (file));
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 (file));
Out.write (Strtoal);
Out.close ();
}
catch (Exception e)
{
E.printstacktrace ();
}
}
public static synchronized void log (String fileName, string[] logmessages)
{
Try
{
File Folder = new file (RootPath);
if (!folder.exists ())
{
Folder.mkdir ();
}
File File = new file (RootPath + "\" + fileName + ". Log");
if (!file.exists ())
{
File.createnewfile ();
}
BufferedReader in = new BufferedReader (new FileReader (file));
String str = "";
String strtoal = "";
while ((str = in.readline ())!= null)
{
Strtoal + = (str + ENTER);
}
for (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 (file));
Out.write (Strtoal);
Out.close ();
}
catch (Exception e)
{
E.printstacktrace ();
}
}
public static void Main (String args[])
{
AndyLogger.log ("bug223", "Timeisjjja");
String[] LogMessages = {"111", "222", "333"};
AndyLogger.log ("bug223", logmessages);
}
}