java代码硬盘使用比例 java代码硬盘使用比例是多少( 三 )


long capacity = parseVolumeCapacity(line, captionToIndex);
long freeSpace = parseVolumeFreeSpace(line, captionToIndex);
return new DiskUsage(caption,
((capacity - freeSpace) / (double) capacity) * 100);
}
private static boolean isValidDriveLetter(String driveLetter) {
if (driveLetter.length() != 2) {
return false;
}
return Character.isUpperCase(driveLetter.charAt(0));
}
private static int parseVolumeDriveType(String line,
MapString, Integer captionToIndex) {
String str = line.substring(captionToIndex.get(CAP_DRIVE_TYPE),
captionToIndex.get(CAP_FREE_SPACE));
return Integer.parseInt(str.trim());
}
private static String parseVolumeDriveLetter(String line,
MapString, Integer captionToIndex) {
String str = line.substring(captionToIndex.get(CAP_DRIVE_LETTER),
captionToIndex.get(CAP_DRIVE_TYPE));
return str.trim();
}
private static String parseVolumeCaption(String line,
MapString, Integer captionToIndex) {
String str = line.substring(captionToIndex.get(CAP_CAPTION),
captionToIndex.get(CAP_DRIVE_LETTER));
return str.trim();
}
private static long parseVolumeCapacity(String line,
MapString, Integer captionToIndex) {
String str = line.substring(captionToIndex.get(CAP_CAPACITY),
captionToIndex.get(CAP_CAPTION));
return Long.parseLong(str.trim());
}
private static long parseVolumeFreeSpace(String line,
MapString, Integer captionToIndex) {
String str = line.substring(captionToIndex.get(CAP_FREE_SPACE));
return Long.parseLong(str.trim());
}
private static class DiskUsageComparator implements ComparatorDiskUsage {
@Override
public int compare(DiskUsage o1, DiskUsage o2) {
return o1.caption.compareTo(o2.caption);
}
}
private static class DiskUsage {
public String caption;
public double usage;
public DiskUsage(String caption, Double usage) {
this.caption = caption;
this.usage = usage;
}
}
}
Java获取服务器磁盘负载率1、在远程server里搭建一个http服务java代码硬盘使用比例,并支持某种服务端语言(如.net或php之类)
2、用服务端语言获取到服务器的磁盘信息java代码硬盘使用比例,把结果输出
3、在本地用JS写一段AJAX脚本,远程请求服务端写好的程序,得到结果,并展示给用户
html
head
title提取硬盘序列号/title
script
function disk() {//硬盘序列号 信息
var locator = new ActiveXObject ("WbemScripting.SWbemLocator");
var service = locator.ConnectServer(".");
var properties = service.ExecQuery("SELECT * FROM Win32_DiskDrive");
var e = new Enumerator (properties);
document.write("table border=1");
for (;!e.atEnd();e.moveNext ())
{
var p = e.item ();
document.write("tr");
document.write("td" + p.signature + "/td");
document.write("/tr");
}
document.write("/table");
}
/script
/head
body
input type="button" value="https://www.04ip.com/post/硬盘序列号" onclick="disk()"
/body
/html
在这上找的代码:
对于写过ASP或.net 的人来说,通过asp或.net 语言来获得客户端的硬件信息是很熟悉的.但如何通过javascript这种客户端脚本来获得客户端的信息呢?请看以下实例:
!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
html
head
titlejavascript获得客户端硬件信息-;/title
meta name="GENERATOR" content="Microsoft Visual Studio .NET
7.1"
meta name="vs_targetSchema"
content=""
script id=clientEventHandlersJS language=javascript
!--
function Button2_onclick() {//CPU 信息
var locator = new ActiveXObject ("WbemScripting.SWbemLocator");

推荐阅读