在共享位置上从Java创建目录

时间:2013-10-09 15:53:51

标签: java runtime directory java-io filewriter

我似乎无法弄清楚为什么我无法从Java程序创建特定位置的目录。 具体是 - 我的计算机的文件夹在网络上共享。

代码:

File xmlDirectory = new File(sXMLOutputPath);

 /*
  * TODO: if multiple threads arive at the 1st if, if will evaluate to true, 
  * then 1st thread would create directory, and the 2nd being .01 sec later, will fail   
  *  to create directory and have exception
  * SOLUTION:  Provide additional if exists, so that 2nd thread will recognize that it 
  *  was created.  
  */
 if (!xmlDirectory.exists()){
     if (!xmlDirectory.mkdirs()){
       if (!xmlDirectory.exists()){
          throw new BillAdminException("Failed to create xml directory: " + 
           sXMLOutputPath);
       }
     }
 }

这是服务器端代码

总结一下 - 如果我分享我的foder C:\ folder \ etc - 并将它作为JVM选项传递给程序,服务器端程序“追加”\ xml \ 333 \ 333.xml“到它,并且假设在MY PC上创建该xml文件。首先它创建一个结构C:\ folder \ etc \ xml \ 333 \,然后创建333.xml。如果C创建C:\ folder \ etc \ xml \ 333失败:\ folder \ etc以“\ myMachine \ etc”形式作为共享位置传递,但是如果我在其他机器“\ OtherMachine \ etc”上创建该结构,则工作正常。如果我将其作为“C:\ folder \”传递等等“(绝对的,不是共享的形式)它可以正常工作,在执行代码的服务器上创建目录和文件。我需要在我的机器(客户端)上创建它。共享文件夹时我做错了什么。
P.S - 这个功能大约在2个月前工作。但是,从那时起,文件夹属性就可以进行调整。但不是java代码。

P.S 2:这不是我从JVM选项中传递的唯一共享文件夹。还有2个,但用于阅读(不创建子文件夹) 谢谢,求助

P.S 3:我得到的错误是:

Failed to create xml directory: \\myMachine\etc\xml/333/ 

我闻到腥味,是“333”之前的斜线是颠倒的。但是,代码没有变化,所以之前也会发生同样的变化。

0 个答案:

没有答案