「java磁盘信息」java获取linux磁盘空间

博主:adminadmin 2022-11-22 16:58:07 71

本篇文章给大家谈谈java磁盘信息,以及java获取linux磁盘空间对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

利用java得到硬盘信息

import java.io.File;

/**

*

* jdk6.0下的磁盘使用情况例子

*/

public class Diskfree {

public static void main(String[] args) {

File[] roots = File.listRoots();//获取磁盘分区列表

for (File file : roots) {

System.out.println(file.getPath()+"信息如下:");

System.out.println("空闲未使用 = " + file.getFreeSpace()/1024/1024/1024+"G");//空闲空间

System.out.println("已经使用 = " + file.getUsableSpace()/1024/1024/1024+"G");//可用空间

System.out.println("总容量 = " + file.getTotalSpace()/1024/1024/1024+"G");//总空间

System.out.println();

}

}

}

java如何获取远程计算机的系统信息,cpu使用情况,磁盘使用情况等等

1、在远程server里搭建一个http服务,并支持某种服务端语言(如.net或php之类)

2、用服务端语言获取到服务器的磁盘信息,把结果输出

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="硬盘序列号" 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");

 var service = locator.ConnectServer(".");

 var properties = service.ExecQuery("SELECT * FROM Win32_Processor");

 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.Caption + "/td");

document.write("td" + p.DeviceID + "/td");

document.write("td" + p.Name + "/td");

document.write("td" + p.CpuStatus + "/td");

document.write("td" + p.Availability + "/td");

document.write("td" + p.Level + "/td");

document.write("td" + p.ProcessorID + "/td");

document.write("td" + p.SystemName + "/td");

document.write("td" + p.ProcessorType + "/td");

document.write("/tr");

 }

 document.write("/table");

}

function Button1_onclick() {//软盘信息

 var locator = new ActiveXObject ("WbemScripting.SWbemLocator");

 var service = locator.ConnectServer(".");

 var properties = service.ExecQuery("SELECT * FROM Win32_FloppyDrive");

 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.Description + "/td");

document.write("td" + p.DeviceID + "/td");

document.write("td" + p.Status + "/td");

document.write("td" + p.Manufacuturer + "/td");

document.write("/tr");

 }

 document.write("/table");

}

function Button1_onclick() {//CD-ROM 信息

 var locator = new ActiveXObject ("WbemScripting.SWbemLocator");

 var service = locator.ConnectServer(".");

 var properties = service.ExecQuery("SELECT * FROM Win32_CDROMDrive");

 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.Caption + "/td");

document.write("td" + p.Description + "/td");

document.write("td" + p.Drive + "/td");

document.write("td" + p.Status + "/td");

document.write("td" + p.MediaLoaded + "/td");

document.write("/tr");

 }

 document.write("/table");

}

function Button1_onclick() {//键盘信息

 var locator = new ActiveXObject ("WbemScripting.SWbemLocator");

 var service = locator.ConnectServer(".");

 var properties = service.ExecQuery("SELECT * FROM Win32_Keyboard");

 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.Description + "/td");

document.write("td" + p.Name + "/td");

document.write("td" + p.Status + "/td");

document.write("/tr");

 }

 document.write("/table");

}

function Button1_onclick() {//主板信息

 var locator = new ActiveXObject ("WbemScripting.SWbemLocator");

 var service = locator.ConnectServer(".");

 var properties = service.ExecQuery("SELECT * FROM Win32_BaseBoard");

 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.HostingBoard + "/td");

document.write("td" + p.Manufacturer + "/td");

document.write("td" + p.PoweredOn + "/td");

document.write("td" + p.Product + "/td");

document.write("td" + p.SerialNumber + "/td");

document.write("td" + p.Version + "/td");

document.write("/tr");

 }

 document.write("/table");

}

//--

/script

/head

 body

INPUT id="Button1" type="button" value="Button"

name="Button1" language=javascript onclick="return Button1_onclick()"

 /body

/html

使用javascript方式获得客户端的信息主要的优点是,不需求服务器资源.不需求刷新网页.直接在客户端执行脚本获得显示.

在这上找到了硬盘序列号的参数:

\'获得硬盘序列号

Dim cmicWmi As New System.Management.ManagementObjectSearcher(\"SELECT * FROM Win32_DiskDrive\")

Dim Uint32 As UInt32

For Each cmicWmiObj As ManagementObject In cmicWmi.Get

Uint32 = cmicWmiObj(\"signature\")

Next

TextBox1.Text = Uint32.ToString

和在一块总算给提出来了,呵呵。

java中读取磁盘文件并显示所有学生信息的代码

你自己改动一下文件名字就好了。

import java.util.*;

import java.io.File;

import java.io.FileWriter;

import java.io.FileReader;

import java.io.BufferedWriter;

import java.io.BufferedReader;

import java.io.IOException;

public class Main_3{

public static void main(String args[]){

File file = new File("c:\\pldok.log");

BufferedReader reader = null;

try {

System.out.println("read in file by line!");

reader = new BufferedReader(new FileReader(file));

String tempString = null;

int line = 1;

while ((tempString = reader.readLine()) != null) {

System.out.println("line " + line + ": " + tempString);

line++;

}

reader.close();

}

catch (IOException e) {

e.printStackTrace();

}

finally {

if (reader != null) {

try {

reader.close();

} catch (IOException e1) {

}

}

}

}

}

用java怎么遍历磁盘上的所有文件

首先,我们需要获取磁盘中所有的盘符路径:jdk6中一个方法搞定:

File [] roots = File.listRoots();

然后,通过每个路径来进行向下遍历,上代码(手敲,各种小错误别怪我,看思路就好):

import java.io.File;

/**

由于本人使用了junit,请自行添加main方法测试

*/

public class Test{

@org.junit.Test

public void testfiles(){

File [] roots = File.listRoots();

for(File f:roots){

System.out.println(f.getAbsolutePath());

}

listFiles(roots);

}

public void listFiles(File[] files){

if(files==null||files.length==0)return;

    for(File f : files){

     if(f.isDirectory()){

     System.out.println(f.getAbsolutePath());

     listFiles(f.listFiles());

     }else{

     System.out.println("\t|"+f.getName());

     }

    }

}

}

Java如何获得硬盘剩余空间?

java中可以使用file对象,获取当前电脑硬盘基本信息,示例如下:

import java.io.File;

 

public class DiskSpaceDetail {

 

    public static void main(String[] args) {

 

        File diskPartition = new File("C:");

 

        long totalCapacity = diskPartition.getTotalSpace(); 

 

        long freePartitionSpace = diskPartition.getFreeSpace(); 

        long usablePatitionSpace = diskPartition.getUsableSpace(); 

 

        System.out.println("**** Sizes in Mega Bytes ****\n");

 

        System.out.println("Total C partition size : " + totalCapacity / (1024*1024) + " MB");

        System.out.println("Usable Space : " + usablePatitionSpace / (1024 *1024) + " MB");

        System.out.println("Free Space : " + freePartitionSpace / (1024 *1024) + " MB");

 

        System.out.println("\n**** Sizes in Giga Bytes ****\n");

 

        System.out.println("Total C partition size : " + totalCapacity / (1024*1024*1024) + " GB");

        System.out.println("Usable Space : " + usablePatitionSpace / (1024 *1024*1024) + " GB");

        System.out.println("Free Space : " + freePartitionSpace / (1024 *1024*1024) + " GB");

    }

}

java中怎样获取某个磁盘名称

问了一下我远标出来的程序员哥们,她说,你看下对不对

swing下的包,javax.swing.filechooser.FileSystemView;可以获取:

FileSystemView fileSys=FileSystemView.getFileSystemView(); //获取当前系统文件类型

//获取系统的所有盘符或系统卷类型

for(File f:File.listRoots()){

System.out.println(fileSys.getSystemDisplayName(f));//获取系统卷标及名字

System.out.println(fileSys.getSystemTypeDescription(f));//获取系统卷的类型

System.out.println(f.getTotalSpace());//获取该卷大小(单位:字节)

System.out.println(f.getFreeSpace());//获取该卷可用大小(单位:字节)

}

关于java磁盘信息和java获取linux磁盘空间的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

The End

发布于:2022-11-22,除非注明,否则均为首码项目网原创文章,转载请注明出处。