Search code examples
javafilesmbjcifs

Convert SmbFile to File how to?


I am trying to read a file from a server. I am getting it with smb, but i need it to be a File[] array.

SmbFile dir = new SmbFile(url, auth);
for (SmbFile f : dir.listFiles()) {
    System.out.println(f.getName());
}

What I was thinking of doing a

SmbFile tmp = new SmbFile(url:"./");
tmp.createNewFile();
dir.copyTo(tmp);

File csvFile = new File("./");

Solution

  • SmbFile home = new SmbFile(ServerURL, authentication);
    
    SmbFile[] files = home.listFiles((fileList, name) -> name.endsWith(".dat"));
    

    Then just iterate through the files.