File f = new File("C:\\Temp\\Example.txt");
f.createNewFile();
On将在Temp文件夹中创建名为“Example.txt”的新文件。 现在我的问题是如何在Mac OS X中提供文件路径。
我尝试提供:
File f = new File("\\Users\\pavankumar\\Desktop\\Testing\\Java.txt");
f.createNewFile();
但对我没用。
答案 0 :(得分:15)
Forward slash "/" must be used to get the file path here. Use:
Heart Rate Sensor: Heart Rate Belt
答案 1 :(得分:6)
Please use File.separator to be independent from the OS:
<Subscription code="12345678R1">
<userAccount>40000005b</userAccount>
<offerTemplate>Test</offerTemplate>
<subscriptionDate>2015-05-06</subscriptionDate>
<terminationDate></terminationDate>
</Subscription>
Or use org.apache.commons.io.FilenameUtils.normalize:
if (!Uri.TryCreate("http://www-.ageofautism.com/2010/01/wakefields-science-proven-valid-again-in-new-study-that-replicates-findings.html", UriKind.Absolute, out url) || url.Host == string.Empty)
throw new InvalidUrlException(inputUrl);
Either of them can be used (the second option needs library)
答案 2 :(得分:1)
There is a { 4, 100 }
system-dependent constant that you should use to provide some portability to your Java code.
答案 3 :(得分:1)
On Linux, Mac OS X and other *nix flavours, the folder separator is typedef
not template <class T, int A, int B>
class ObjTypedef{
typedef OftenUsedType<T, A, B> R;
}
template <class T, int A, int B>
class Obj : public ObjTypedef<T, A, B>{
}
, so no need to escape anything /
.
Also, you can use the \
folder for your temporary files.
Finally, on *nix systems, the home directory is usually represented some/path/of/folders
or is in the environment variable /tmp
.