-
Notifications
You must be signed in to change notification settings - Fork 0
/
StringExtractor.java
34 lines (30 loc) · 1003 Bytes
/
StringExtractor.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import java.io.File;
import java.io.FileNotFoundException;
import java.util.*;
public class StringExtractor {
private static Boolean textExtractor(String path,String key) throws FileNotFoundException{
File file = new File(path);
Scanner sc = new Scanner(file);
while (sc.hasNextLine()) {
String line = sc.nextLine();
if(line.contains(key)){
sc.close();
return true;
}
}
sc.close();
return false;
}
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the file path: ");
String path = sc.nextLine();
System.out.print("Enter the String to be found: ");
String key = sc.nextLine();
if(textExtractor(path, key))
System.out.println("String Found..!!");
else
System.out.println("String Not Found..!!");
sc.close();
}
}