在Java中创建文件时,如何在Mac OS X中提供文件路径? [英] How do I provide a file path in Mac OS X while creating a file in Java?
本文介绍了在Java中创建文件时,如何在Mac OS X中提供文件路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
File f = new File("C:\\Temp\\Example.txt");
f.createNewFile();
执行时,将在Temp
文件夹中创建一个名为"Example.txt"的新文件.如何在Mac OS X中提供文件路径?
On executing, a new file named "Example.txt" will be created in the Temp
folder. How do I 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屋!
查看全文