filenotfoundexception Java FileOutputStream Windows/Linux
为什么我得到了这个密码:
OutputStream output = new FileOutputStream("res/" + new java.util.Date().toString() +".properties");
我在大学(笔记本电脑-Ubunutu)和在家(台式电脑-windows)都在编写代码。 我将Eclipse项目与github和EGit同步
现在我无法在我的Windows机器上执行这行代码,但它仍在我的笔记本电脑上运行。。完全相同的代码
获取错误:
java.io.FileNotFoundException: res\Thu Jan 08 15:54:39 CET 2015.properties (Die Syntax für den Dateinamen, Verzeichnisnamen oder die Datenträgerbezeichnung ist falsch)
和:at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(Unknown Sourc
at java.io.FileOutputStream.<init>(Unknown Source)
# 1 楼答案
new java.util.Date().toString()
将以以下格式给出日期它包含: windows中的名称不允许使用该字符。但是你可以在linux中使用它们
因此,如果你想在两个平台上使用相同的东西,你必须改变日期的格式,可能是使用
SimpleDateFormat
或其他东西 e、 g# 2 楼答案
Windows不允许文件名中使用冒号“:”
# 3 楼答案
我认为问题在于
:
不是Windows中路径名的有效字符从MSDN的文章“Naming Files, Paths, and Namespaces”中: