-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSearchFromFile.java
38 lines (25 loc) · 980 Bytes
/
SearchFromFile.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
35
36
37
38
import java.util.*;
import java.io.*;
public class SearchFromFile
{
public static void main(String [] args){
File file = new File("numbers.txt");
Scanner kb = new Scanner(System.in);
System.out.print("Enter the content you are looking for: ");
String find = kb.next();
Scanner scanner;
String Filename = "numbers.txt";
try{
scanner = new Scanner(file).useDelimiter(",");
while(scanner.hasNext()){
final String lineFromFile = scanner.nextLine();
if(lineFromFile.contains(find)){
System.out.println(find);
continue;
}
}
}catch(Exception e){
System.err.println("Exception Here!");
}
}
}