0

我似乎无法弄清楚为什么我不能从 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”到它,并且应该创建它xml 文件在我的电脑上。首先它创建一个结构 C:\folder\etc\xml\333\,然后创建 333.xml。如果 C:\folder 创建 C:\folder\etc\xml\333 失败\etc 以“\myMachine\etc”的形式作为共享位置传递,但如果我在其他机器“\OtherMachine\etc”上创建该结构,则可以正常工作。如果我将其作为“C:\folder\etc”传递(绝对,不是共享形式)它将工作正常,在执行代码的服务器机器上创建目录和文件。我需要在我的机器(客户端)上创建它。共享文件夹时我做错了什么。
PS - 这个功能大约在 2 个月前工作。但是,从那时起,文件夹属性可能已被调整。不过,不是java代码。

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

PS 3:我得到的错误是:

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

我闻起来很腥,是“333”之前的斜线被颠倒了。但是,代码没有变化,所以以前也会发生同样的事情。

4

0 回答 0