HI i am trying to print string in revrse order as i am coding it at jsp page log file is look like,
[1322110800] LOG ROTATION: DAILY
[1322110800] LOG VERSION: 2.0
[1322110800] CURRENT HOST STATE:arsalan.hussain;DOWN;HARD;1;CRITICAL - Host Unreachable (192.168.1.107)
[1322110800] CURRENT HOST STATE: localhost;UP;HARD;1;PING OK - Packet loss = 0%, RTA = 0.06 ms
[1322110800] CURRENT HOST STATE: musewerx-72c7b0;UP;HARD;1;PING OK - Packet loss = 0%, RTA = 0.27 ms
code is,
List<String> data = new LinkedList<String>();
String strpath="/var/nagios.log";
FileReader fr = new FileReader(strpath);
BufferedReader br = new BufferedReader(fr);
String ch;
int time=0;
String Conversion="";
do {
ch = br.readLine();
Conversion=String.valueOf(inf.stringToLong(ch));
Date d = new Date(Long.valueOf(Conversion));
Pattern pt = Pattern.compile("\\[(\\d+)\\]");
Matcher m = pt.matcher(ch);
if (m.find()) {
Date dt = new Date(Long.parseLong(m.group(1)) * 1000);
SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yyyy HH:mm:ss");
ch = m.replaceFirst('['+ sdf.format(dt) +']');
}
out.print(ch+"<br/>");
} while (ch != null);
fr.close();
then i tried it by adding this in my code,
String[] arr=ch.split("\\[");
time=arr.length;
for(int num=time;num>=0;num--)
{
out.print(arr[num]+"<br/>");
}
now above code look like after adding this code ,
List<String> data = new LinkedList<String>();
String strpath="/var/nagios.log";
FileReader fr = new FileReader(strpath);
BufferedReader br = new BufferedReader(fr);
String ch;
int time=0;
String Conversion="";
do {
ch = br.readLine();
Conversion=String.valueOf(inf.stringToLong(ch));
Date d = new Date(Long.valueOf(Conversion));
Pattern pt = Pattern.compile("\\[(\\d+)\\]");
Matcher m = pt.matcher(ch);
if (m.find()) {
Date dt = new Date(Long.parseLong(m.group(1)) * 1000);
SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yyyy HH:mm:ss");
ch = m.replaceFirst('['+ sdf.format(dt) +']');
}
String[] arr=ch.split("\\[");
time=arr.length;
for(int num=time;num>=0;num--)
{
out.print(arr[num]+"<br/>");
}
//out.print(ch+"<br/>");
} while (ch != null);
fr.close();
BUT result is exception in JSP ???
Hopes for you reply
Best Regards