View difference between Paste ID: Y2vDPr4C and U5ra9GfA
SHOW: | | - or go back to the newest paste.
1
package task;
2
3
import java.io.*;
4
5
class SearchPhrase {
6
7
	// walk to root way
8-
	public void walk(String path) throws IOException {
8+
	public void walk(String path, String whatFind) throws IOException {
9
10
		File root = new File(path);
11
		File[] list = root.listFiles();
12
		for (File titleName : list) {
13
			if (titleName.isDirectory()) {
14-
				walk(titleName.getAbsolutePath());
14+
				walk(titleName.getAbsolutePath(), whatFind);
15-
				// System.out.println( "Dir:" + titleName.getAbsoluteFile() );
15+
16
				if (read(titleName.getAbsolutePath()).contains(whatFind)) {
17-
				System.out.println("File:" + titleName.getAbsoluteFile());
17+
					System.out.println("File: " + titleName.getAbsoluteFile());
18
				}
19
			}
20
		}
21
	}
22
23
	// Read file as one line
24
	public static String read(String fileName) {
25
		StringBuilder strBuider = new StringBuilder();
26
		try {
27-
					fileName).getAbsoluteFile()));
27+
28
					fileName)));
29
			String strInput;
30
			while ((strInput = in.readLine()) != null) {
31
				strBuider.append(strInput);
32
				strBuider.append("\n");
33
			}
34
35
			in.close();
36
		} catch (IOException e) {
37
			e.printStackTrace();
38
		}
39
40
		return strBuider.toString();
41
	}
42-
	public static int searchPhrase(String fileName, String what) {
42+
43-
		int n = fileName.length(); // Длина строки, в которой происходит поиск
43+
44-
		int m = what.length(); // Длина подстроки
44+
45
		SearchPhrase example = new SearchPhrase();
46-
		// Формирование таблицы сдвигов
46+
47-
		int[] table = new int[m];
47+
48-
		table[0] = 0;
48+
			example.walk(
49-
		int shift = 0;
49+
					"C:\\Documents and Settings\\User\\Java Hangman\\Java\\Anton",
50-
		for (int q = 1; q < m; q++) {
50+
					"programmed");
51-
			while (shift > 0 && what.charAt(shift) != what.charAt(q)) {
51+
52-
				shift = table[shift - 1];
52+
53
		}
54-
			if (what.charAt(shift) == what.charAt(q))
54+
55-
				shift++;
55+