① java mac 安装路径在哪
Mac OS自带的JDK 6:/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java。看到有朋友说OS 10.10删除了自带的JDK 6,但是我升级10.10之后还是能找到该路径,专不知道是属否需要重新在苹果网站下载JDK 6呢? 2. Oracle的JDK 7/8 (1)用/usr/libexec/java_home命令得到的Java Home路径是:/Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents/Home,这是我之前在Oracle网站下载的jdk 8 update 20。 (2)在Java控制面板显示的路径:/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java,版本是Java 8 update 25。
② 如何使用Java代码获取Android和ios移动终端Mac地址
通过设备开通wifi连接获取Mac地址是最可取的,代码如下: ?123456789101112131415161718 /** * 设备开通WiFi连接,通过wifiManager获取Mac地址 * * @author 高焕杰 */public static String getMacFromWifi(Context context){ ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); State wifiState = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState(); if(wifiState == NetworkInfo.State.CONNECTED){//判断当前是否使用wifi连接 WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); if (!wifiManager.isWifiEnabled()) { //如果当前wifi不可用 wifiManager.setWifiEnabled(true); } WifiInfo wifiInfo = wifiManager.getConnectionInfo(); return wifiInfo.getMacAddress(); } return null;}除了上面这种方法,网上还给出了另外两种方法: 1、通过调用Linux的busybox命令获取Mac地址: ?1234567891011121314151617181920 /** * 通过调用Linux的busybox命令获取Mac地址 * * @author 高焕杰 */private static String getMacFromCallCmd(){ try { String readLine = ; Process process = Runtime.getRuntime().exec(busybox ifconfig); BufferedReader bufferedReader = new BufferedReader (new InputStreamReader(process.getInputStream())); while ((readLine = bufferedReader.readLine ()) != null) {//执行命令cmd,只取结果中含有HWaddr的这一行 if(readLine.contains(HWaddr)){ return readLine.substring(readLine.indexOf(HWaddr)+6, readLine.length()-1); } } }catch(Exception e) { //如果因设备不支持busybox工具而发生异常。 e.printStackTrace(); } return null;}注意:这种方法在Android Pad中可以准确获取到的Mac地址,但是在Android手机中无法准确获取到。 2、通过查询记录了MAC地址的文件(文件路径:“/proc/net/arp”)获取Mac地址: ?123456789101112131415161718192021222324252627282930313233343536373839404142 /** * 通过查询记录了MAC地址的文件(文件路径:“/proc/net/arp”)获取Mac地址 * * @author 高焕杰 */ private static String getMacFromFile(Context context){ String readLine =; BufferedReader bufferedReader = null; try { bufferedReader = new BufferedReader(new FileReader(new File(/proc/net/arp))); int rollIndex = 0; while((readLine = bufferedReader.readLine())!=null){ if(rollIndex == 1){ break; } rollIndex = rollIndex + 1; } } catch (IOException e) { e.printStackTrace(); } finally { if (bufferedReader != null) { try { bufferedReader.close(); } catch (IOException e) { e.printStackTrace(); } } } if(readLine !=null && readLine.length()>1){ String[] subReadLineArray = readLine.split( ); int rollIndex = 1; for(int i = 0; i < subReadLineArray.length; ++i){ if(!TextUtils.isEmpty(subReadLineArray[i])){ if(rollIndex == 4){ return subReadLineArray[i]; } rollIndex = rollIndex + 1; } } } return null; }注意:无论在Android Pad中还是在Android手机中,这种方法都无法准确获取到Mac地址。
③ java怎么获取系统mac地址
首先,创建工程,包,和一个类。在此不加详述,我们直接看代码。这里,我把这个类命名为GetMacAddr这里,最最关键的就是这里这个方法。我们通过NetworkInterface这个类来操作。也就是通过getLocalHost()方法先得到本机IP,然后调用getHardwareAddress()方法得到一个byte数组的地址。我们把六位地址传到一个byte数组里面,然后输出来就是。不多废话,看代码:private void getMACAddr()throws SocketException, UnknownHostException {// 获得IPNetworkInterface netInterface =NetworkInterface.getByInetAddress(InetAddress.getLocalHost());// 获得Mac地址的byte数组byte[] macAddr = netInterface.getHardwareAddress();System.out.print("MAC Addr:\t");// 循环输出for (byte b : macAddr) {// 这里的toHexString()是自己写的格式化输出的方法,见下步。System.out.print(toHexString(b) + " ");}}上一步骤中,为什么会出现一个toHexString()方法呢?因为可能10进制转16进制时候可能会出现单字符,所以,如果有出现单字符的情况,我们在其前面添加一个“0”做占位符。这也是为了视觉的直观,也夹带着个人的习惯。private static String toHexString(int integer) {// 将得来的int类型数字转化为十六进制数String str = Integer.toHexString((int) (integer & 0xff));// 如果遇到单字符,前置0占位补满两格if (str.length() == 1) {str = "0" + str;}return str;}
④ mac怎么看jdk安装路径
()用/usr/libexec/java_home命令得到的Java Home路径是:/Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents/Home,这是之前在Oracle网站下载的jdk 8 update 20。
(2)在Java控制面板显示的路径:/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java,版本是Java 8 update 25。
⑤ java中获取文件路径的几种方式
获取当前类的所在工程路径;如果不加“/”File f = new File(this.getClass().getResource("").getPath());System.out.println(f);结果:C:\Documents%20and%20Settings\Administrator\workspace\projectName\bin\com\test获取当前类的绝对路径;第二种:File directory = new File("");//参数为空String courseFile = directory.getCanonicalPath() ;System.out.println(courseFile);结果:C:\Documents and Settings\Administrator\workspace\projectName获取当前类的所在工程路径;第三种:URL xmlpath = this.getClass().getClassLoader().getResource("selected.txt");System.out.println(xmlpath);结果:file:/C:/Documents%20and%20Settings/Administrator/workspace/projectName/bin/selected.txt获取当前工程src目录下selected.txt文件的路径第四种:System.out.println(System.getProperty("user.dir"));结果:C:\Documents and Settings\Administrator\workspace\projectName获取当前工程路径第五种:System.out.println( System.getProperty("java.class.path"));结果:C:\Documents and Settings\Administrator\workspace\projectName\bin获取当前工程路径
⑥ mac系统,java编程中文件流的路径是如何写的
看看这个,我昨天刚写的: import java.io.BufferedOutputStream;import java.io.File;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.FileReader;import java.io.IOException;import java.io.PrintWriter;import java.util.Scanner;public class AddList {private String filePath = "";private String bakPath = "";private String content = "";Scanner sc = new Scanner(System.in);public String readFile(){content = "";if (isNull(filePath)) {System.out.println("文件存储路径:");filePath = sc.nextLine();}File file = new File(filePath);FileReader fr = null;try {if (file.exists()) {fr = new FileReader(file);char[] chars = new char[1024];int n = 0;while((n = fr.read(chars)) != -1){String string = new String(chars, 0, n);content = content + string;}} else {System.out.println("文件不存在");}} catch (Exception e) {e.printStackTrace();} finally {if (fr != null) {try {fr.close();} catch (IOException e) {e.printStackTrace();}}}return content;}public void writeFile(String path){File file = new File(path);FileOutputStream fos = null;mkDirs(path);try {fos = new FileOutputStream(file);BufferedOutputStream bos = new BufferedOutputStream(fos);PrintWriter pw = new PrintWriter(bos, true);pw.print(content);pw.flush();} catch (FileNotFoundException e) {e.printStackTrace();} finally {if (fos != null) {try {fos.close();} catch (IOException e) {e.printStackTrace();}}}}public void writeFile(){if (isNull(filePath)) {System.out.println("文件存储路径:");filePath = sc.nextLine();}File file = new File(filePath);FileOutputStream fos = null;mkDirs(filePath);try {fos = new FileOutputStream(file);BufferedOutputStream bos = new BufferedOutputStream(fos);PrintWriter pw = new PrintWriter(bos, true);pw.print(content);pw.flush();} catch (FileNotFoundException e) {e.printStackTrace();} finally {if (fos != null) {try {fos.close();} catch (IOException e) {e.printStackTrace();}}}}public void mkDirs(String filepath){if (filepath.indexOf("\\") != -1) {filepath = filepath.replaceAll("\\", "/");}int n = filepath.indexOf("//");String path = filepath.substring(0, n) + "//";filepath = filepath.substring(filepath.indexOf("//") + 1, filepath.length());String[] files = filepath.split("/");for (int i = 0; i < files.length – 1; i++) {path = path + files[i];File file = new File(path);if (!file.exists()) {file.mkdir();}}}public void addImfor(){System.out.println("——–增加记录———");String name = "";String tel = "";String email = "";content = readFile();while(true){System.out.println("姓名:");name = sc.next();System.out.println("电话:");tel = sc.next();System.out.println("Email:");email = sc.next();content = content + name + "<>" + tel + "<>" + email +"<==>";System.out.println("0、Exit 1、继续");int i = sc.nextInt();if (i == 0) {break;}}writeFile();}public void deleteImfor(){System.out.println("———删除记录———");String name = "";String[] imfors = null;content = readFile();while(true){System.out.println("你要删除的姓名是:");name = sc.next();if (content.indexOf(name) != -1) {imfors = content.split("<==>");for (int i = 0; i < imfors.length; i++) {if (imfors[i].indexOf(name) != -1) {imfors[i] = "";}}content = "";for (int i = 0; i < imfors.length; i++) {if (!isNull(imfors[i])) {content = content + imfors[i] + "<==>";}}writeFile();System.out.println("删除成功");} else {System.out.println("此人不存在");}System.out.println("0、Exit 1、继续");int i = sc.nextInt();if (i == 0) {break;}}}public void viewAll(){System.out.println("———-显示所有————");content = readFile();if (!isNull(content)) {String[] imfors = content.split("<==>");System.out.println("姓名\t电话\tEmail");for (int i = 0; i < imfors.length; i++) {String[] imfor = imfors[i].split("<>");for (int j = 0; j < imfor.length; j++) {System.out.print(imfor[j] + "\t");}System.out.println();}} else {System.out.println("暂时还没有记录");}}public void queryImfor(){System.out.println("———-查找记录———–");content = readFile();if (!isNull(content)) {String result = "";String[] imfors = null;String[] imfor = null;String name = "";boolean bool = false;while(true){result = "";System.out.println("请输入关键字(按姓名查找):");name = sc.next();bool = false;if (content.indexOf(name) != -1) {imfors = content.split("<==>");for (int i = 0; i < imfors.length; i++) {if (imfors[i].indexOf(name) != -1) {imfor = imfors[i].split("<>");if (imfor[0].equals(name)) {bool = true;result = result + imfors[i] + "<==>";}}}if (bool) {imfors = result.split("<==>");System.out.println("姓名\t电话\tEmail");for (int i = 0; i < imfors.length; i++) {imfor = imfors[i].split("<>");for (int j = 0; j < imfor.length; j++) {System.out.print(imfor[j] + "\t");}System.out.println();}} else {System.out.println("无此人信息");}} else {System.out.println("无此人信息");}System.out.println("0、Exit 1、继续");int i = sc.nextInt();if (i == 0) {break;}}} else {System.out.println("文件还没有记录");}}public void (){System.out.println("———-备份———–");content = readFile();if (isNull(bakPath)) {System.out.println("备份全路径:");bakPath = sc.next();}writeFile(bakPath);System.out.println("备份成功");}public boolean isNull(String string){if (null == string || "" == string || 0 == string.length()) {return true;} else {return false;}}public static void main(String[] args) {AddList add = new AddList();Scanner sc = new Scanner(System.in);int operater = 0;while(true){System.out.println("选择功能:\n1、增加记录 2、删除记录 3、显示所有 4、查询记录 5、备份 6、退出");operater = sc.nextInt();if (1 == operater) {add.addImfor();} else if (2 == operater) {add.deleteImfor();} else if (3 == operater) {add.viewAll();} else if (4 == operater) {add.queryImfor();} else if (5 == operater) {add.();} else if (6 == operater) {System.out.println("谢谢使用");break;}}}}
⑦ JAVA中如何得到文件路径
java文件中获得路径Thread.currentThread().getContextClassLoader().getResource("") //获得资源文件(.class文件)所在路径ClassLoader.getSystemResource("")Class_Name.class.getClassLoader().getResource("")Class_Name.class .getResource("/") Class_Name.class .getResource("") // 获得当前类所在路径System.getProperty("user.dir") // 获得项目根目录的绝对路径System.getProperty("java.class.path") //得到类路径和包路径打印输出依次如下:file:/F:/work_litao/uri_test/WebContent/WEB-INF/classes/file:/F:/work_litao/uri_test/WebContent/WEB-INF/classes/file:/F:/work_litao/uri_test/WebContent/WEB-INF/classes/file:/F:/work_litao/uri_test/WebContent/WEB-INF/classes/file:/F:/work_litao/uri_test/WebContent/WEB-INF/classes/com/xml/imp/F:\work_litao\uri_testF:\work_litao\uri_test\WebContent\WEB-INF\classes;F:\work_litao\uri_test\WebContent\WEB-INF\lib\dom4j.jar
⑧ mac 怎么看jdk 安装路径
Mac OS自带的JDK 6:/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java。看到有朋友说OS 10.10删除了自带的JDK 6,但是升级10.10之后还是能找到该路径,版不知道是否需要重新在苹果权网站下载JDK 6 。2. Oracle的JDK 7/8 (1)用/usr/libexec/java_home命令得到的Java Home路径是:/Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents/Home,这是之前在Oracle网站下载的jdk 8 update 20。(2)在Java控制面板显示的路径:/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java,版本是Java 8 update 25。
⑨ java 获取当前文件的路径,路径全名
我觉抄得如果只是为了得到路径,那袭491064739的回答其实已经给你思路了,就是传入个File f,然后String s = f.getAbsolutePath();得到绝对路径!不过,似乎你问的是Path后,我的思路是传入两个参数,一个workspace的路径,一个是File f 。伪代码如下:public String getPathInfo(String workspace,File file) throw Exception{ String path = file.geAbsolute(); //绝对路径 path.replaceAll("\\\\","/"); //把\ 替换成 / workspace.replaceAll("\\\\","/"); String info = path.subString(workspace.length-1); //-1是留下/ //因为是绝对路径,所以文件名最前面的就是workspace,把前面那段去掉就是Path后的了 return info;}大致上逻辑就是这样吧
未经允许不得转载:山九号 » java获取苹果系统文件路径|java 获取当前文件的路径