本文实例讲述了 Java 获取 Mac : :
/** getMacAddress .java ** Deskripsi: Dapatkan Mac Addreess ** @Author Hadeslee ** Dibuat pada 2007-9-27, 9: 11: 15 ** Untuk mengubah templat ini, pilih Tools | Templat* dan buka templat di editor.*/Package test2; impor java.io.bufferedReader; impor java.io.ioException; impor java.io.inputStreamReader; /****/kelas publik getMaCaddress {public static string getMaCadDress () {string address = ""; String os = system.getProperty ("os.name"); System.out.println (OS); if (os! = null && os.startswith ("windows")) {coba {processBuilder pb = new ProcessBuilder ("ipconfig", "/all"); Proses p = pb.start (); BufferedReader BR = BufferedReader baru (inputStreamReader baru (p.getInputStream ())); Garis string; while ((line = br.readline ())! = null) {if (line.indexof ("alamat fisik")! = -1) {int index = line.indexof (":"); alamat = line.substring (indeks+1); merusak; }} br.close (); pengembalian alamat.trim (); } catch (ioException e) {}} alamat kembali; } public static void main (string [] args) {System.out.println ("" + test.getMacAddress ()); }}
希望本文所述对大家的 Java 程序设计有所帮助。