首页编程java编程java mac 桌面路径是什么意思(mac系统,java编程中文件流的路径是如何写的)

java mac 桌面路径是什么意思(mac系统,java编程中文件流的路径是如何写的)

编程之家2023-10-14107次浏览

今天给各位分享java mac 桌面路径是什么意思的知识,其中也会对mac系统,java编程中文件流的路径是如何写的进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

java mac 桌面路径是什么意思(mac系统,java编程中文件流的路径是如何写的)

mac系统,java编程中文件流的路径是如何写的

看看这个,我昨天刚写的: import java.io.BufferedOutputStream;

import java.io.File;

import java.io.FileNotFoundException;

java mac 桌面路径是什么意思(mac系统,java编程中文件流的路径是如何写的)

import java.io.FileOutputStream;

import java.io.FileReader;

import java.io.IOException;

java mac 桌面路径是什么意思(mac系统,java编程中文件流的路径是如何写的)

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 copy(){

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.copy();

} else if(6== operater){

System.out.println("谢谢使用");

break;

}

}

}

}

java安装好了怎么打开 mac

方法/步骤

1

查询登录eclipse官网,由于我是用Java开发的所以步骤如下:

2

1.找到“Eclipse IDE for java Developers”此处右上角会根据你当前使用的系统自动选择,Mac下就会自动选择位“Mac OS X(Cocoa)”

3

2.然后点击右边的“Mac OS X 64bit”(这里我的Air是i5处理器可以用64位的),根据你的电脑也可以选择“Mac OS X 32bit”进行下载。

4

3.进入下载界面后,点击绿色下载箭头,浏览器进行下载。(下载后的格式为压缩格式,需先解压)

4.下载完成后(下载后的格式为压缩格式,需先解压),在解压后的eclipse文件夹中找到eclipse.app,点击打开。

5.打开后如图1所示,成功进入后,如图2所示

6.界面左上角有“welcome”的页面名,将该页面关闭,会出现下图

现在,正式恭喜你可以开始编写java了,现在我来做一个示范,比如说输出一个“hello world!”的经典例题。

1.在左边栏目框里,点击右键,选择“New”,在出现的快捷菜单里点击“java project“,会出现下图

2.将光标移至“project name”填写框最前端,给自己的项目取一个名字。在这里我将“project name”填写为“first test”。然后点击“Finish”。OK,现在项目已建成,名字为“first test”。

3.下面,需要建一个类,点击"src",如图1,右键,选择“new”,再选择“class”。出现下图2

4.然后输入类的名字。点击“Finish”。注意,main要记得勾选。

5.OK,开始输入代码吧!注意哦,主框架代码系统会自动显示,无需我们自己输入,这一点还是很省事的!

6.代码输入完毕,点击菜单栏“Run”按钮,OK啦,我们就可以在最下面一栏”Console“界面看到我们的运行结果啦!

请问java如何获取手机mac地址

以windows举例。

运行命令" cmd ipconfig/all"就会出现以下结果

Physical Address.........: 20-CF-30-9A-60-EE

java就能过这样的命令来获取。以下是示例。

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

public class TestMac

{

public static void main(String[] args){

System.out.println("Operation System="+ getOsName());

System.out.println("Mac Address="+ getMACAddress());

System.out.println("通过ip获取mac"+getMACAddress("192.168.1.101"));

}

public static String getOsName(){

String os="";

os= System.getProperty("os.name");

return os;

}

public static String getMACAddress(){

String address="";

String os= getOsName();

if(os.startsWith("Windows")){

try{

String command="cmd.exe/c ipconfig/all";

Process p= Runtime.getRuntime().exec(command);

BufferedReader br= new BufferedReader(new InputStreamReader(p.getInputStream()));

String line;

while((line= br.readLine())!= null){

if(line.indexOf("Physical Address")> 0){

int index= line.indexOf(":");

index+= 2;

address= line.substring(index);

break;

}

}

br.close();

return address.trim();

} catch(IOException e){

}

} else if(os.startsWith("Linux")){

String command="/bin/sh-c ifconfig-a";

Process p;

try{

p= Runtime.getRuntime().exec(command);

BufferedReader br= new BufferedReader(new InputStreamReader(p.getInputStream()));

String line;

while((line= br.readLine())!= null){

if(line.indexOf("HWaddr")> 0){

int index= line.indexOf("HWaddr")+"HWaddr".length();

address= line.substring(index);

break;

}

}

br.close();

} catch(IOException e){

}

}

address= address.trim();

return address;

}

public static String getMACAddress(String ipAddress){

String str="", strMAC="", macAddress="";

try{

Process pp= Runtime.getRuntime().exec("nbtstat-a"+ ipAddress);

InputStreamReader ir= new InputStreamReader(pp.getInputStream());

LineNumberReader input= new LineNumberReader(ir);

for(int i= 1; i< 100; i++){

str= input.readLine();

if(str!= null){

if(str.indexOf("MAC Address")> 1){

strMAC= str.substring(str.indexOf("MAC Address")+ 14,

str.length());

break;

}

}

}

} catch(IOException ex){

return"Can't Get MAC Address!";

}

//

if(strMAC.length()< 17){

return"Error!";

}

macAddress= strMAC.substring(0, 2)+":"+ strMAC.substring(3, 5)

+":"+ strMAC.substring(6, 8)+":"+ strMAC.substring(9, 11)

+":"+ strMAC.substring(12, 14)+":"

+ strMAC.substring(15, 17);

//

return macAddress;

}

}

剑天梦的回答原理和我这个一样,都是通过Process执行命令。我直接补充到答案里了。不过

我这边运行那个命令出来的结果很多,那么花的时间就长了。优点是能够获取别人的mac地址。

关于java mac 桌面路径是什么意思的内容到此结束,希望对大家有所帮助。

知乎 java web用什么书 大学java课程vivox27发布(vivox27发布会直播回放)