0

ハードディスク内のファイルを正常に検索するプログラムをコーディングします。しかし今、私はそれにもう1つの機能を追加したいと考えています。私のプログラムがこれらの検索されたファイルを http 経由でサーバーにアップロードすることを望みます。では、このための戦略を説明できる人はいますか?

ここに私の小さなプログラムがあります

        public class Find {

    public static class Finder extends SimpleFileVisitor<Path> {

        private final PathMatcher matcher;
        private int numMatches = 0;

        Finder(String pattern) 
        {
            matcher = FileSystems.getDefault().getPathMatcher("glob:" + pattern);
        }

        // Compares the glob pattern against
        // the file or directory name.
        void find(Path file) 
        {
            Path name = file.getFileName();
            if (name != null && matcher.matches(name)) 
            {
                numMatches++;
                System.out.println(file);
            }
        }

        // Prints the total number of
        // matches to standard out.
        void done() 
        {
            System.out.println("Matched: "
                + numMatches);
        }

        // Invoke the pattern matching
        // method on each file.
        //@Override
        public FileVisitResult visitFile(Path file,
                BasicFileAttributes attrs) 
        {
            find(file);
            return CONTINUE;
        }

        // Invoke the pattern matching
        // method on each directory.
        //@Override
        public FileVisitResult preVisitDirectory(Path dir,
                BasicFileAttributes attrs) 
        {
            find(dir);
            return CONTINUE;
        }

        //@Override
       public FileVisitResult visitFileFailed(Path file,IOException exc) 
        {
            System.err.println(exc);
            return CONTINUE;
        }
    }

    static void usage()
    {
        System.err.println("java Find <path>" +" -name \"<glob_pattern>\"");
        System.exit(-1);
    }

    public static void main(String[] args)throws IOException 
    {

        if (args.length < 1 ) 
        {
            usage();
        } 
        Iterable<Path> root;
        root = FileSystems.getDefault().getRootDirectories();
        for (Path startingDir : FileSystems.getDefault().getRootDirectories()) 
        {
          String pattern = args[0];

        Finder finder = new Finder(pattern);
        Files.walkFileTree(startingDir, finder);
        //finder.done();
        }
    }

}
4

1 に答える 1