我正在创建一个这样的文件
try {
File file = new File(workingDir, obj.getName() + ".xls");
outputStream = new FileOutputStream(file);
} catch (FileNotFoundException ex) {
ex.printStackTrace();
}
我得到了
java.io.FileNotFoundException: ..\a\relative\path\obj_name.xls (The parameter is incorrect)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileOutputStream.<init>(Unknown Source)
“参数不正确”是什么意思?我验证的路径名存在;它不应该只创建文件名吗?这是在Windows机器上。该代码在基于 unix 的系统上运行时不会出现此错误。
更新
已验证输出流正在尝试写入的文件是否存在。还验证了该文件是可写的。大惊小怪之后,我删除了实际路径并传入了文件名(不需要)并且有效。所以这个问题与路径有关。我需要转义路径中的字符吗?
最佳答案
这看起来像一个 reported bug在 Windows 机器上。
在正常情况下,诸如其中包含冒号 (:) 且未引用驱动器号的路径之类的内容会导致此消息。
关于java - 通常,当 java 返回 "The parameter is incorrect"时,这意味着什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1208566/