我正在编写一个程序,我试图在当前目录中创建一个新的文本文件,然后向它写入一个字符串。但是,试图创建的文件,这个代码块时:java.io.IOException:系统找不到指定的路径写入文本文件
//Create the output text file.
File outputText = new File(filePath.getParentFile() + "\\Decrypted.txt");
try
{
outputText.createNewFile();
}
catch (IOException e)
{
e.printStackTrace();
}
是给我这个错误消息:
java.io.IOException: The system cannot find the path specified
at java.io.WinNTFileSystem.createFileExclusively(Native Method)
at java.io.File.createNewFile(Unknown Source)
at code.Crypto.decrypt(Crypto.java:55)
at code.Crypto.main(Crypto.java:27)
正因为如此,我不能写入文件,因为它自然是不存在的。我在这里做错了什么?
如何'filePath'构建? – hmjd
File filePath = fc.getSelectedFile(); – Inglonias
'outputText'构造之前'filePath.getParentFile()'的值是什么? – hmjd