一般来讲,要用java得到硬盘空间,有3种方法:
1. 调用system的command,然后分析得到的结果,这种方法有很强的系统依赖性,linux下和win下要分别写程序
下面是一个win下的例子,编译成功之后,运行java Diskspace yourdir(比如c:\)
import java.io.BufferedReader;
import java.io.InputStreamReader;
/**
* Determine free disk space for a given directory by
* parsing the output of the dir command.
* This class is inspired by the code at
* Works only under Windows under certain circumstances.
* Yes, it´s that shaky.
* Requires Java 1.4 or higher.
* @[EMAIL ...[ 查看全文 ]