通常,当java返回“参数不正确"时,这是什么意思? [英] Typically, what does it mean when java returns a "The parameter is incorrect"
问题描述
我正在创建一个像这样的文件
I am creating a file like so
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的系统上,代码可以正常工作而不会出现此错误.
What does "the parameter is incorrect" mean? The pathname I validated exists; shouldn't it just create the file name? This is on a windows machine. The code works without this error on unix based systems.
更新
验证输出流正在尝试写入的文件是否存在.还验证了该文件可写.经过大惊小怪之后,我删除了实际路径,只是传入了文件名(不需要),并且可以正常工作.因此,问题与路径有关.我需要对路径中的字符进行转义吗?
Verified that the file exists that the output stream is attempting to write to. Also verified that the file is writable. After much fussing, I removed the actual path and just passed in the file name (not desired) and that works. So the issue has something to do with the path. Do I need to escape the characters in the path?
推荐答案
这看起来像是在正常情况下,类似路径中带有冒号(:)且未引用驱动器号的情况都会引起此消息.
Under normal situations, something like a path that has a colon (:) in it which does not refer to a drive letter would cause this message.
这篇关于通常,当java返回“参数不正确"时,这是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!