Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java-从windows网络路径复制文件夹_Java_Windows_File_Smb - Fatal编程技术网

Java-从windows网络路径复制文件夹

Java-从windows网络路径复制文件夹,java,windows,file,smb,Java,Windows,File,Smb,我正在尝试从受用户名和密码保护的windows网络共享文件夹复制该文件夹 String url = "smb://40.123.xx.xx/sharefolder/"; NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(null, "username", "pas."); SmbFile dir = new SmbFile(url, auth); if(d

我正在尝试从受用户名和密码保护的windows网络共享文件夹复制该文件夹

String url = "smb://40.123.xx.xx/sharefolder/"; 
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(null, "username", "pas.");
SmbFile dir = new SmbFile(url, auth);
if(dir.exists()) {
File[] directories = new File("\\40.123.xx.xx\\sharefolder")
                .listFiles(file -> file.isDirectory() && file.getName().matches("[0-9]{6}"));

for (File getDirectory : directories) {
Path folder = Paths.get(getDirectory.getAbsolutePath());
                BasicFileAttributes attr = Files.readAttributes(folder, BasicFileAttributes.class);
//          System.out.println("creationTime: " + attr.creationTime());
                System.out.println("creationDate : " + sdf.format(attr.creationTime().toMillis()));
    try {
//      FileUtils.copyDirectoryToDirectory(new File(getDirectory.getAbsolutePath()),new File("F:\\localFolder"));
                    
        } catch (IOException e) {
            e.printStackTrace();
            }
        
    }
}
但是File[]目录返回null,而不是返回所有文件夹路径


如何访问网络文件夹并将文件复制到本地路径。

您的UNC路径名开头只有一个转义反斜杠,因此不是远程文件系统的有效UNC路径,因此您正在扫描
\40.123.xx.xx\sharefolder
,而它应该扫描
\\40.123.xx.xx\sharefolder

System.out.println(new File("\\40.123.xx.xx\\sharefolder"))
\40.123.xx.xx\sharefolder        (WRONG)

System.out.println(new File("\\\\40.123.xx.xx\\sharefolder"))
\\40.123.xx.xx\sharefolder       (CORRECT)