- public static String getHostIP() {
- String hostIp = null;
- try {
- Enumeration nis = NetworkInterface.getNetworkInterfaces();
- InetAddress ia = null;
- while (nis.hasMoreElements()) {
- NetworkInterface ni = (NetworkInterface) nis.nextElement();
- Enumeration<InetAddress> ias = ni.getInetAddresses();
- while (ias.hasMoreElements()) {
- ia = ias.nextElement();
- if (ia instanceof Inet6Address) {
- continue;// skip ipv6
- }
- String ip = ia.getHostAddress();
- if (!"127.0.0.1".equals(ip)) {
- hostIp = ia.getHostAddress();
- break;
- }
- }
- }
- } catch (SocketException e) {
- Log.i("yao", "SocketException");
- e.printStackTrace();
- }
- return hostIp;
- }
package main import ( "fmt" "syscall" ) func main() { fmt.Println(DiskUsage("./")) } func DiskUsage(path string) uint64 { fs := syscall.Statfs_t{} err := syscall.Statfs(path, &fs) if err != nil { return 0 } return fs.Bfree * uint64(fs.Bsize) } //All space = fs.Blocks * uint64(fs.Bsize) //Free space = fs.Bfree * uint64(fs.Bsize) //Used space= fs.All - disk.Free
评论
发表评论