Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.nio.file.*;
- import java.nio.file.attribute.*;
- public class Writtalble {
- public static void main(String args[]) {
- String dirname = args[0];
- DirectoryStream.Filter<Path> how =
- new DirectoryStream.Filter<Path>() {
- public boolean accept(Path filename) throws IOException {
- if(Files.isWritable(filename)) {
- return true;
- } else {
- return false;
- }
- }
- };
- try (DirectoryStream<Path> dirs =
- Files.newDirectoryStream(Paths.get(dirname), how)) {
- System.out.println("Directory of: " + dirname);
- for(Path entry : dirs) {
- BasicFileAttributes attribs =
- Files.readAttributes(entry, BasicFileAttributes.class);
- if(attribs.isDirectory()) {
- System.out.print("DIR ");
- } else {
- System.out.print(" ");
- }
- System.out.println(entry.getName(1));
- }
- } catch(InvalidPathException e) {
- System.out.println("1");
- return;
- } catch(IOException e) {
- System.out.println(e);
- return;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement