日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

获取Linux/Unix文件系统信息

發布時間:2023/11/27 生活经验 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 获取Linux/Unix文件系统信息 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

?設計一套SAP監控系統

http://blog.csdn.net/bayaci/archive/2009/10/13/4666456.aspx

顯示系統df(linux )/ bdf (hpunix)的信息


執行代碼,獲取諸如bdf /usr命令后的信息:
DiskInfo diskInfo = new DiskInfo();
diskInfo.info(directory);
long used = diskInfo.getUsed();
long free = diskInfo.getAvailable();
long kbyte = diskInfo.getKbyte();






代碼如下:
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.StringTokenizer;
?
?
public class DiskInfo {

?? /** OS line separator. */
???? static final String NL = System.getProperty( "line.separator" );

?? private static long getLong( String value ) throws NumberFormatException {
?????? try {
?????????? return Long.parseLong( value );
?????? }
?????? catch( NumberFormatException nfe ) {
?????????? throw new NumberFormatException( "On value "+value+": "+nfe.getMessage() );
?????? }
?? }


?? private String fileSystem ;
?? private String mounted ;
private? long used = 0L;
private long kbyte = 0L;
private long available = 0L;

?? public?? void info(String directory? ) throws IOException {

????? InputStream stream = null;
???? // Connection connection = null; // Database Connection Object

?

?
???????? // to handle standard outputs
???????? final byte[] buf = new byte[1024];
???????? String[] strings;
???????? int i;
???????? int size;

?
???????? // note OS name
???????? final String osName = System.getProperty( "os.name" );

??????? // System.out.println( "system is? " + osName);
????????
????????
???????? if( "Linux".equals( osName ) ) {
??????????? final Process p = Runtime.getRuntime().exec( "df " + directory );
??????????? stream = p.getInputStream();
??????????? final int count = stream.read( buf, 0, buf.length );

??????????? String delim = NL;

??????????? final StringTokenizer st = new StringTokenizer( new String( buf, 0, count ), delim,
true );

??????????? int lineNum = 1;
??????????? int field = 0;

??????????? while( st.hasMoreTokens() ) {
??????????????? final String token = st.nextToken(delim);
??????????????? //System.out.println( "token is? " + token);
??????????????? if( lineNum < 2 ) {
??????????????????? if( NL.equals( token ) ) {
??????????????????????? lineNum++;
??????????????????????? if( lineNum == 2 ) {
??????????????????????????? delim = " " + NL;
??????????????????????? }
??????????????????? }
??????????????? }// else
??????????????? if( !" ".equals( token ) ) {
??????????????????? field++;
??????????????? ??? if( field == 0 ) {
??????????????? ??? ??? setFileSystem (?? token? );
??????????????????? } else
??????????????????? if( field == 2 ) {
??????????????????? ??? setUsed ( getLong( token ));
??????????????????? } else
??????????????????? if( field == 3 ) {
??????????????????? ??? setAvailable( getLong( token ));
??????????????????? }
??????????????? }
??????????? }
???????? }
???????? else
???????? if( "HP-UX".equals( osName ) ) {
??????????? final Process p = Runtime.getRuntime().exec( "bdf " + directory );
??????????? stream = p.getInputStream();
??????????? final int count = stream.read( buf, 0, buf.length );

??????????? String delim = NL;

??????????? final StringTokenizer st = new StringTokenizer( new String( buf, 0, count ), delim,
true );

??????????? int lineNum = 1;
??????????? int field = 0;

??????????? while( st.hasMoreTokens() ) {
??????????????? final String token = st.nextToken(delim);
??????????????? if( lineNum < 2 ) {
??????????????????? if( NL.equals( token ) ) {
??????????????????????? lineNum++;
??????????????????????? if( lineNum == 2 ) {
??????????????????????????? delim = " " + NL;
??????????????????????? }
??????????????????? }
??????????????? } else
??????????????? if( !" ".equals( token ) ) {
??????????????????? field++;
????????????????????
???????????????????
???????????????????
??????????????? ??? if( field == 0 ) {
??????????????? ??? ??? setFileSystem (?? token? );
??????????????????? } else
??????????????? ??? if( field == 3 ) {
??????????????? ??? ??? setUsed ( getLong( token ));
??????????????????? } else
??????????????????? if( field == 4 ) {
??????????????????? ??? setAvailable( getLong( token ));
??????????????????? }
??????????????? }
??????????? }
???????? } else {
??????????? throw new RuntimeException( "Unknown OS name: " + osName + " to implement..." );
???????? }
?
???????? setKbyte ( getUsed() + getAvailable());
???????? setMounted(directory );
?
?
?? }

?? private void setUsed(long used) {
??? this.used = used;
}

public long getUsed() {
??? return used;
}

private void setKbyte(long kbyte) {
??? this.kbyte = kbyte;
}

public long getKbyte() {
??? return kbyte;
}

private void setAvailable(long available) {
??? this.available = available;
}

public long getAvailable() {
??? return available;
}

private void setFileSystem(String fileSystem) {
??? this.fileSystem = fileSystem;
}

public String getFileSystem() {
??? return fileSystem;
}

private void setMounted(String mounted) {
??? this.mounted = mounted;
}

public String getMounted() {
??? return mounted;
}

?
?
??
??
}



轉載于:https://www.cnblogs.com/peter9/archive/2009/10/15/2362208.html

總結

以上是生活随笔為你收集整理的获取Linux/Unix文件系统信息的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。