How to quickly find added / removed files?

前端 未结 10 2608
情深已故
情深已故 2020-12-25 08:28

I am writing a little program that creates an index of all files on my directories. It basically iterates over each file on the disk and stores it into a searchable database

10条回答
  •  长发绾君心
    2020-12-25 08:55

    How about something like this:

    private static String execute( String command ) throws IOException  { 
        Process p = Runtime.getRuntime().exec( "cmd /c " + command );
        InputStream i = p.getInputStream();
        StringBuilder sb = new StringBuilder();
        for(  int c = 0 ; ( c =  i.read() ) > -1  ; ) {
            sb.append( ( char ) c );
        }
        i.close();
        return sb.toString();
    }
    

    ( There is a lot of room for improvement there, since that version reads one char at a time: You can pick a better version from here to read the stream faster )

    And you use as argument:

    "dir /b /s M:\tests\"
    

    If this is going to be used in a running app ( rather and being an standalone app ) you can discount the "warm up" time of the JVM, that's about 1 - 2 secs depending on your hardware.

    You could give it a try to see what's the impact.

提交回复
热议问题