[英]Folder and file are not getting created by Java code under Linux, but it works for Windows
I have a few questions about Java's io.file class 我对Java的io.file类有一些疑问
You can use the static field File.separator
or, better, use the nio Paths class like this: 您可以使用静态字段
File.separator
或更好地使用nio Paths类,如下所示:
File f = Paths.get( "dir1", "dir2", "dir3" ).toFile();
To get something to refer to the absolute path, start the String arguments with a File.separator, which you might get also with nio with this method: 为了让某些东西可以引用绝对路径,可以使用File.separator来启动String参数,使用nio这个方法也可以得到它:
http://docs.oracle.com/javase/7/docs/api/java/nio/file/FileSystem.html#getSeparator%28%29 http://docs.oracle.com/javase/7/docs/api/java/nio/file/FileSystem.html#getSeparator%28%29
Under Windows: 在Windows下:
File file = new File("C:\\TempFolder\\Images");
File file = new File("C:/TempFolder/Images"); // Because Windows soemtimes is nice.
Under Linux: 在Linux下:
File file = new File("/TempFolder/Images");
The reason having two backslashes ( \\\\
), is that in strings a backslash must be escaped: \\t
being a tab character etcetera. 之所以具有两个反斜杠(
\\\\
),是因为在字符串中必须转义一个反斜杠: \\t
是制表符等。
There are no drive letters in Linux, if that was your question. 如果这是您的问题,则Linux中没有驱动器号。 For temporary files you might use File.createTemporaryFile or createTemporaryDirectory.
对于临时文件,您可以使用File.createTemporaryFile或createTemporaryDirectory。
Directories on other computers may also be used without drive letters, but with UNC paths: 其他计算机上的目录也可以不带驱动器号,但带UNC路径使用:
Windows : Windows :
\\Server\Directory\Directory
"\\\\Server\\Directory\\Directory"
Linux : Linux :
//Server/Directory/Directory
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.