This sample code is modeled after Oracles sample code in Managing Metadata (File and File Store Attributes).
It lists the files and directories in the current directory together with the alternate data streams.
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.UserDefinedFileAttributeView;
public class Xd2 {
public static void main(String[] args) throws IOException {
Path p = Paths.get(".");
Files.list(p).forEach(file -> {
UserDefinedFileAttributeView view = Files.
getFileAttributeView(file, UserDefinedFileAttributeView.class);
try {
// print file size and name
System.out.printf("%8d %s%n", Files.size(file) , file);
for (String name : view.list()) {
// list alternate data stream size and name
System.out.format(" %8d %s\n", view.size(name), name);
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}
});
}
}