读取日志的java代码 读取日志是什么意思

怎么用java读取windows系统日志您好读取日志的java代码 , 很高兴为您解答 。
获取相关信息读取日志的java代码的简单的方法
import java.io.*;
import com.sun.management.OperatingSystemMXBean;
import sun.management.ManagementFactory;
public class Tst{
publicstatic String pt="D:\\abc.txt";
publicTst(){
}
public static void main(String[] args) throws Exception{
//free和use和total均为KB
longfree=0;
longuse=0;
longtotal=0;
intkb=1024;
Runtimert=Runtime.getRuntime();
total=rt.totalMemory();
free=rt.freeMemory();
use=total-free;
System.out.println("系统内存已用的空间为:"+use/kb+"MB");
System.out.println("系统内存的空闲空间为:"+free/kb+"MB");
System.out.println("系统总内存空间为:"+total/kb+"MB");
OperatingSystemMXBeanosmxb = (OperatingSystemMXBean)
ManagementFactory.getOperatingSystemMXBean();
longphysicalFree=osmxb.getFreePhysicalMemorySize()/kb;
longphysicalTotal=osmxb.getTotalPhysicalMemorySize()/kb;
longphysicalUse=physicalTotal-physicalFree;
Stringos=System.getProperty("os.name");
System.out.println("操作系统的版本:"+os);
System.out.println("系统物理内存已用的空间为:"+physicalFree+"MB");
System.out.println("系统物理内存的空闲空间为:"+physicalUse+"MB");
System.out.println("总物理内存:"+physicalTotal+"MB");
// 获得线程总数
ThreadGroup parentThread;
for(parentThread = Thread.currentThread().getThreadGroup();
parentThread
.getParent() != null; parentThread=
parentThread.getParent())
;
inttotalThread = parentThread.activeCount();
System.out.println("获得线程总数:"+totalThread);
}
}
// 3.操作系统信息
// a)取到当前操作系统的名称:
public String getPlatformName() {
String hostname = "";
try
{
hostname = InetAddress.getLocalHost().getHostName();
} catch
(Exception exc) {
Sigar sigar = new Sigar();
try {
hostname =
sigar.getNetInfo().getHostName();
} catch (SigarException e)
{
hostname = "localhost.unknown";
} finally
{
sigar.close();
}
}
【读取日志的java代码 读取日志是什么意思】return hostname;
}
// b)取当前操作系统的信息
public void testGetOSInfo() {
OperatingSystem OS =
OperatingSystem.getInstance();
// 操作系统内核类型如:
386、486、586等x86
System.out.println("OS.getArch() = " +
OS.getArch());
System.out.println("OS.getCpuEndian() = "
+OS.getCpuEndian());//
System.out.println("OS.getDataModel() = "
+OS.getDataModel());//
// 系统描述
System.out.println("OS.getDescription()
= " +OS.getDescription());
System.out.println("OS.getMachine() = "
+OS.getMachine());//
// 操作系统类型
System.out.println("OS.getName() = " +
OS.getName());
System.out.println("OS.getPatchLevel() = "
+OS.getPatchLevel());//
// 操作系统的卖主
System.out.println("OS.getVendor()
= " + OS.getVendor());
//
卖主名称
System.out
.println("OS.getVendorCodeName() = "
+OS.getVendorCodeName());
//
操作系统名称
System.out.println("OS.getVendorName() = "
+OS.getVendorName());
//
操作系统卖主类型
System.out.println("OS.getVendorVersion() = "
+OS.getVendorVersion());
//
操作系统的版本号
System.out.println("OS.getVersion() = "
+OS.getVersion());
}
// 4.资源信息(主要是硬盘)
//
a)取硬盘已有的分区及其详细信息(通过sigar.getFileSystemList()来获得FileSystem列表对象读取日志的java代码 , 然后对其进行编历):

推荐阅读