Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.rs.worldserver.util;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.nio.file.*;
- import java.nio.file.attribute.BasicFileAttributes;
- import java.util.ArrayDeque;
- /**
- * @author Stan
- */
- public class Scanner {
- public static final String CHARACTER_FILE_PATH = "./savedgames/";
- public static void main(final String... args) throws IOException {
- search();
- }
- public static void search() throws IOException{
- BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
- System.out.print("Enter your desired keyword: ");
- String keyword = reader.readLine();
- System.out.println("Started scanning all files...");
- long start = System.currentTimeMillis();
- try {
- Path path = Paths.get(CHARACTER_FILE_PATH);
- Files.walkFileTree(path, new SimpleFileVisitor<Path>() {
- @Override
- public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IOException {
- System.out.print(path);
- if(new String(Files.readAllBytes(path)).contains(keyword))
- matches.add(path.toString());
- return FileVisitResult.CONTINUE;
- }
- });
- } catch (IOException e) {
- System.out.println("Make sure this is in the same directory as "+CHARACTER_FILE_PATH);
- }
- long duration = System.currentTimeMillis() - start;
- System.out.println("Found "+matches.size()+" matches for the keyword "+keyword);
- matches.forEach(System.out::println);
- System.out.println("The scan toke " + duration + "ms to complete.");
- System.out.print("For another scan type -r: ");
- matches.clear();
- if(reader.readLine().equalsIgnoreCase("-r"))
- search();
- reader.close();
- }
- private static ArrayDeque<String> matches = new ArrayDeque<String>(200);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement