|
|
do you have alternate idea?
|
|
|
|
|
Such as what? You cannot capture information from a remote system unless that system first collects the information, and either lets you request it, or it sends it to you in some way.
|
|
|
|
|
Might want to clarify that other answer however since it actually depends on what the server is running.
A 'server' with java often means a JEE container. And most if not all of them have management APIs that allows access to usage statistics. So something like Tomcat, JBoss, WebLogic, etc might already have a way to get it via a http server or an API.
|
|
|
|
|
JDK provide tool to monitor the remote java application's memory use, here is where you can find the tool:
after you download the JDK, it will located in the tools directory.
|
|
|
|
|
can we find cpu utilization of server from client using sigar API?
|
|
|
|
|
What does the documentation say?
|
|
|
|
|
it has no method for get cpu utilization from client
Do you have any idea how to do?
|
|
|
|
|
|
|
Hi
I have a directory where log txt files are logged. Each log file has the following title date format 20180114.log, which is yyymmdd.
I want to search for data in the preceding file (date) so if the current date file is 20180114.log, I want to search the previous day 20180113.log, and then output the data i search for in anther text file.
How do I achieve this in java? any code examples I can follow?
I made a start by displaying the list of the files in the directory but could do with some help to achieve the above
public static void main(String[] args) {
File currentDir = new File("\\\\directory Path");
displayDirectoryContents(currentDir);
}
public static void displayDirectoryContents(File dir) {
try {
File[] files = dir.listFiles();
for (File file : files) {
System.out.println(" file:" + file.getCanonicalPath());
}
} catch (IOException e) {
e.printStackTrace();
}
}
thanks in advance
|
|
|
|
|
You can google using the following
java wildcard file search
|
|
|
|
|
You just need to list all files with the .log extension and find the last but one. So since array indices go from 0 to (count_of_entries - 1), the one at offset (count - 2) will be the last but one.
|
|
|
|
|
Thanks for the suggestions.
I made a start now by listing all the files with the extension .log and it works.
since the files are in yyyymmdd.log format, i only want to list the last one - 1. then copy it to another file called logged.log for instance. Could you please help achieve this with the code below?. The code below navigate to the directory and list all files with the extension .log. The printed output is:
20180118.Log
20180117.Log
20180116.Log
So I am interested in the second one: 20180117.Log
import java.util.List;
import java.io.File;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.regex.Pattern;
class search
{
public static void main(String[] args) {
String WILD_CARD = "";
List <File> fileList = new LinkedList<File>();
File folder = new File("d:\\");
File[] listOfFiles = folder.listFiles();
if(WILD_CARD!=null) {
Pattern wildCardPattern = Pattern.compile(".*"+WILD_CARD+"(.*)?.log",Pattern.CASE_INSENSITIVE);
for(File file: listOfFiles) {
java.util.regex.Matcher match = wildCardPattern.matcher(file.getName());
while(match.find()){
String fileMatch = match.group();
if(file.getName().equals(fileMatch)) {
fileList.add(file);
}
}
}
}
else
fileList = new LinkedList<File>( Arrays.asList(folder.listFiles()));
for (File f: fileList) System.out.println(f.getName());
}
}
|
|
|
|
|
Obviously it is the opposite of what I suggested, as the list is in descending order.
|
|
|
|
|
I just double checked the output printed is in ascending order as shown below:
20180115.LOG
20180116.LOG
20180117.LOG
20180118.LOG
|
|
|
|
|
Then my first suggestion still applies. Is this really so difficult to understand? It seems quite straightforward to me; or maybe I am missing something.
|
|
|
|
|
Yes. Just not sure how to do it in the code
|
|
|
|
|
Just count the entries, or convert the list to an array and use the offset value I suggested.
|
|
|
|
|
Ok. I tried somehting like this so I can print the last file - 1
it prints the file but with the file path as well
Object item = (((Deque<File>) fileList).getLast()-1);
System.out.println(item);
|
|
|
|
|
So you have a working solution.
|
|
|
|
|
Not yet. It prints the path of the file rather than the file
It should print:
20180117.LOG
but it is printing
<pre> d:\20180117.LOG
I only want the file so I can create a copy of it.
Can you try it and see if works for you? may be format issue?
|
|
|
|
|
You just need to use a method to extract just the filename, such as: File (Java Platform SE 7 )[^]. Simple answers like this can usually be found in the documentation.
|
|
|
|
|
class facto
{
public static void main(String args[])
{
System.out.println(dust(5));
}
static int dust(int z)
{
if (z==1||z==2)
{
return 2;
}
else
{
return dust(z-1) * dust(z-2);
}
}
}
modified 16-Jan-18 8:05am.
|
|
|
|
|
Firstly, you never print any of the interim values, and secondly, your calculations are wrong. See Fibonacci numbers[^]
|
|
|
|