java无法在windows 7中创建新文件?
我正在尝试使用windows 7创建新文件java无法在windows 7中创建新文件?,java,io,java-io,Java,Io,Java Io,我正在尝试使用windows 7创建新文件 file.createNewFile() 但是文件没有创建,我得到了以下异常 Message: The system cannot find the path specified Stack Trace: [java.io.IOException: The system cannot find the path specified, at java.io.WinNTFileSystem.createFileExclusively(Native
file.createNewFile()
但是文件没有创建,我得到了以下异常
Message:
The system cannot find the path specified
Stack Trace:
[java.io.IOException: The system cannot find the path specified,
at java.io.WinNTFileSystem.createFileExclusively(Native Method),
at java.io.File.createNewFile(File.java:883),
at com.mercury.mtf.actions.file.CreateEmptyFileTask.execute(CreateEmptyFileTask.java:56),
at com.mercury.mtf.actions.file.CreateEmptyFileAction.execute(CreateEmptyFileAction.java:42),
at com.mercury.mtf.core.AbstractAction.run(AbstractAction.java:50),
at com.mercury.mtf.core.Unit.runUnitAction(Unit.java:347),
at com.mercury.mtf.core.Unit.executeUnitAction(Unit.java:176),
at com.mercury.mtf.core.Unit.run(Unit.java:121),
at com.mercury.mtf.core.execution.DefaultUnitExecutor.call(DefaultUnitExecutor.java:24),
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303),
at java.util.concurrent.FutureTask.run(FutureTask.java:138),
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:98),
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:207),
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886),
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908),
at java.lang.Thread.run(Thread.java:619)]
我确信该路径存在,但我意识到该文件夹标记为只读。我试图删除只读标志,但无法正常工作。请确保路径分隔符字符正确。。可以使用单正斜杠或双反斜杠。比如说,
File f = new File("C:\\Documents and Settings\\thandasoru\\My Documents\\temp.txt");
f.createNewFile();
确保路径分隔符字符正确。。可以使用单正斜杠或双反斜杠。比如说,
File f = new File("C:\\Documents and Settings\\thandasoru\\My Documents\\temp.txt");
f.createNewFile();
如果文件是临时文件,则可以使用此功能,并且可以忽略所有权限问题:
File.createTempFile("prefix", "suffix")
如果文件是临时文件,则可以使用此功能,并且可以忽略所有权限问题:
File.createTempFile("prefix", "suffix")
使用
File newFile=newFile(folderName+chipItems[i])代码>而不是使用文件newFile=新文件(folderName+chipItems[i],“w”)代码>。那就好了。如果希望提供Unix touch命令等功能,请避免使用文件模式 使用File newFile=新文件(folderName+chipItems[i])代码>而不是使用文件newFile=新文件(folderName+chipItems[i],“w”)代码>。那就好了。如果希望提供Unix touch命令等功能,请避免使用文件模式 这可以使用File.separator
或File.separatorChar
解决。顺便说一句,这两个静态最终字段不遵循Java命名约定。啊,完全正确!我忘了有File.separatorChar属性。上面提到的代码是脏补丁,我想说;-)这可以使用File.separator
或File.separatorChar
解决。顺便说一句,这两个静态最终字段不遵循Java命名约定。啊,完全正确!我忘了有File.separatorChar属性。上面提到的代码是脏补丁,我想说;-)