如何在java中创建文件时在Mac OS X中提供文件路径? [英] How to provide file path in Mac OS X while creating a file in java?

查看:818
本文介绍了如何在java中创建文件时在Mac OS X中提供文件路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

File f = new File("C:\\Temp\\Example.txt");
f.createNewFile();

开启执行名为Example.txt的新文件将在Temp文件夹中创建。
现在我的问题是如何在Mac OS X中提供文件路径。

On Executing a new file named "Example.txt" will be created in Temp folder. Now my question is how to provide the file path in Mac OS X.

我尝试提供:

File f = new File("\\Users\\pavankumar\\Desktop\\Testing\\Java.txt");
f.createNewFile();

但对我没有用。

推荐答案

必须使用正斜杠/来获取文件路径。
使用:

Forward slash "/" must be used to get the file path here. Use:

File f = new File("/Users/pavankumar/Desktop/Testing/Java.txt");
f.createNewFile();

这篇关于如何在java中创建文件时在Mac OS X中提供文件路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆