0

Below is the values stored in File taskname:description:status:priority:Meeting,High,InProgress,client-Meeting

taskname:description:status:priority:Training,High,Going,JavaTraining

taskname:description:status:priority:Interview,high,progress,Fresher Interview taskname:description:status:priority:meeting,low,started,with team

taskname:description:status:priority:meeting,high,inprogress,team

from these i need to search a string value, ex: meeting How can i search it in first occurrence and return it back.

please help

1 Answers1

0

you can use Scanner and string contains method to check the string pattern.

can you check this link

import java.io.*;
import java.util.Scanner;

class searchForName
{
public static void main(String[] args) throws FileNotFoundException {
        String name = "meeting";
        try {
        File file = new File("input.txt");
        Scanner kb = new Scanner(System.in);
        final Scanner scanner = new Scanner(file);
        while (scanner.hasNextLine()) {
                final String lineFromFile = scanner.nextLine();
                if(lineFromFile.contains(name)) {
                // a match!
                System.out.println("I found " +name+ " in file " +file.getName());
                break;
        }
        }
        }
        catch (FileNotFoundException ex)
        {
                System.out.println("File not found");
        }
}
}
Community
  • 1
  • 1
Kamaraj
  • 181
  • 5