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


public
void testFileSystemInfo() throws Exception {
Sigar sigar = new
Sigar();
FileSystem fslist[] = sigar.getFileSystemList();
//String dir
= System.getProperty("user.home");// 当前用户文件夹路径
for (int i = 0; i
fslist.length; i++) {
System.out.println("\n~~~~~~~~~~" + i
+"~~~~~~~~~~");
FileSystem fs = fslist[i];
//
分区的盘符名称
System.out.println("fs.getDevName() = "
+fs.getDevName());
// 分区的盘符名称
System.out.println("fs.getDirName() =
" +fs.getDirName());
System.out.println("fs.getFlags() = " +
fs.getFlags());//
// 文件系统类型读取日志的java代码,比如
FAT32、NTFS
System.out.println("fs.getSysTypeName() = "
+fs.getSysTypeName());
//
文件系统类型名,比如本地硬盘、光驱、网络文件系统等
System.out.println("fs.getTypeName() = "
+fs.getTypeName());
// 文件系统类型
System.out.println("fs.getType() = "
+fs.getType());
FileSystemUsage usage = null;
try {
usage =
sigar.getFileSystemUsage(fs.getDirName());
} catch (SigarException e)
{
if (fs.getType() == 2)
throw
e;
continue;
}
switch (fs.getType()) {
case 0: //
TYPE_UNKNOWN :未知
break;
case 1: //
TYPE_NONE
break;
case 2: // TYPE_LOCAL_DISK : 本地硬盘
//
文件系统总大小
System.out.println(" Total = " +usage.getTotal() +
"KB");
// 文件系统剩余大小
System.out.println(" Free = " +usage.getFree()
+ "KB");
// 文件系统可用大小
System.out.println(" Avail = "
+usage.getAvail() + "KB");
// 文件系统已经使用量
System.out.println(" Used
= " +usage.getUsed() + "KB");
double usePercent = usage.getUsePercent() *
100D;
// 文件系统资源的利用率
System.out.println(" Usage = " + usePercent
+"%");
break;
case 3:// TYPE_NETWORK :网络
break;
case
4:// TYPE_RAM_DISK :闪存
break;
case 5:// TYPE_CDROM
:光驱
break;
case 6:// TYPE_SWAP
:页面交换
break;
}
System.out.println(" DiskReads = "
+usage.getDiskReads());
System.out.println(" DiskWrites = "
+usage.getDiskWrites());
}
return;
}
如若满意 , 请点击右侧【采纳答案】 , 如若还有问题,请点击【追问】
希望读取日志的java代码我的回答对您有所帮助,望采纳!
~ O(∩_∩)O~
java定时读取日志文件import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.RandomAccessFile;
import java.io.ByteArrayInputStream;
class Reader implements Runnable {
Reader(String filename) {
this.filename = filename;
}
private String filename;
private long filelength = 0;
private int count=0;
@Override
public void run() {
while (true) {
try {
File f = new File(filename);
long nowlength = f.length();
long readlength = nowlength - filelength;
if (readlength == 0) {
Thread.sleep(1000);
continue;
}
RandomAccessFile rf = new RandomAccessFile(f, "r");
// 移动文件指针到上次读的最后
rf.seek(filelength);
filelength=nowlength;
byte[] b = new byte[(int) readlength];
rf.read(b, 0, b.length);
rf.close();
BufferedReader br=new BufferedReader(new InputStreamReader(new ByteArrayInputStream(b)));
String str=null;
count++;

推荐阅读