Ing*_*ias 9 java ioexception text-files
我正在编写一个程序,我正在尝试在当前目录中创建一个新的文本文件,然后写一个字符串给它.但是,在尝试创建文件时,这段代码:
//Create the output text file.
File outputText = new File(filePath.getParentFile() + "\\Decrypted.txt");
try
{
outputText.createNewFile();
}
catch (IOException e)
{
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
给我这个错误信息:
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)
Run Code Online (Sandbox Code Playgroud)
因此,我无法写入文件,因为它自然不存在.我在这做错了什么?
如果您已经使用File类,请考虑充分发挥其潜力,而不是自己完成一半的工作:
File outputText = new File(filePath.getParentFile(), "Decrypted.txt");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
22919 次 |
| 最近记录: |