i have few txt files in one folder. i need a program that will open that folder and read all files one by one to find a string and give me output.
so far i got code to do this from only one particular txt file. but i cant make it from many files in a folder.
can anybody help me pls.................
FileReader fr; BufferedReader br;
String result="";
String word= new String();
String target = "friend";
try{ //read one text file
fr = new FileReader ("C:/Users/user/Desktop/java/test.txt");
br = new BufferedReader(fr);
Scanner scan = new Scanner(br);
while(scan.hasNext()){
result = scan.findWithinHorizon(target,0);
if(result!=null) {
word = (scan.next() + scan.findWithinHorizon("", 0));
ArrayList<String> names = new ArrayList<String>();
names.add(word);
for (int i=0; i< names.size() ; i++) {
System.out.println(names.get(i));}