Apache Commons FileUtils.copyURLToFile-无法创建已经存在的目录

时间:2019-05-01 19:28:38

标签: java apache-commons fileutils

我正在尝试下载JSON文件并将其保存到本地目录。目录(/ data / provisioning)已经存在,并已获得776(u = rwx,g = rwx,o = rw)的权限。上级目录(/ data)也已被授予776权限。

我正在使用Apache Commons FileUtils.copyURLToFile(..)方法下载文件,如下所示:

String filePathToSave = "/data/provisioning/nexus_contents.json";
String url = "http://repository.obfuscated.com/nexus/url/to/json/file";

try {
    FileUtils.copyURLToFile(
            new URL(url)
    , new File(filePathToSave),
            5000,
            5000);
} catch (MalformedURLException e) {
    e.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
}

但是,令我惊讶的是,我遇到了这个错误:

  

java.io.IOException:目录'/ data / provisioning'不能为   创建于   org.apache.commons.io.FileUtils.openOutputStream(FileUtils.java:356)     在   org.apache.commons.io.FileUtils.openOutputStream(FileUtils.java:319)     在org.apache.commons.io.FileUtils.copyToFile(FileUtils.java:1552)     在   org.apache.commons.io.FileUtils.copyInputStreamToFile(FileUtils.java:1528)     在org.apache.commons.io.FileUtils.copyURLToFile(FileUtils.java:1506)     在   deployment.download.Downloader.getAndSaveNexusJSON(Downloader.java:26)     在   deployment.test.DeploymentTest.downloader_get_Nexus_JSON(DeploymentTest.java:424)     在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)     在   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     在java.lang.reflect.Method.invoke(Method.java:498)在   org.junit.runners.model.FrameworkMethod $ 1.runReflectiveCall(FrameworkMethod.java:47)     在   org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)     在   org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)     在   org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)     在org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)处   org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)     在   org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)     在org.junit.runners.ParentRunner处$ 3.run(ParentRunner.java:238)在   org.junit.runners.ParentRunner $ 1.schedule(ParentRunner.java:63)在   org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)在   org.junit.runners.ParentRunner.access $ 000(ParentRunner.java:53)在   org.junit.runners.ParentRunner $ 2.evaluate(ParentRunner.java:229)在   org.junit.runners.ParentRunner.run(ParentRunner.java:309)在   org.junit.runner.JUnitCore.run(JUnitCore.java:160)在   com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)     在   com.intellij.rt.execution.junit.IdeaTestRunner $ Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)     在   com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)     在   com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

我在这里想念什么?

0 个答案:

没有答案