Witshaper is the Professional (Computing Skills, English Learning and Soft Skills) Skill Development Training Center. We provide Professional IT Courses and Soft Skill Training in Dehradun to Students, Employees and organization. Who wish to pursue a career in IT Technology. Witshaper is led by a motivated team of IT experts and Soft Skill Professionals. We provide high quality trainings. Our Emphasis is on giving the practical knowledge to the students, so that they will get to know in depth and never forget what they opt, we provide to the students real learning environment. Witshaper prepares students and professionals to be the part of this growing industry. Be a part of Witshaper and get your dreams successful

Tuesday 12 May 2015

java program to check a particular sentence found in the file or not

package newpackage3;


/**
 *
 * @author rajani
 */


import java.io.*;
import java.util.Scanner;
import java.util.regex.MatchResult;
public class Test {
    public static void main(String[] args) throws FileNotFoundException {
        int count=0,count2=0;
        //MatchResult mr;
        Scanner s = new Scanner(new File("amazon.txt"));
         Scanner s1 = new Scanner(new File("amazoncomp.txt"));
        while (null != s.findWithinHorizon("java", 0)) {
            count=1;
            MatchResult mr = s.match();
           // System.out.printf("Word found: %s at index %d to %d.%n", mr.group(),
                  //  mr.start(), mr.end());
        }
        while (null != s1.findWithinHorizon("java", 0)) {
            count2=1;
            MatchResult mr = s1.match();
            //System.out.printf("Word found: %s at index %d to %d.%n", mr.group(),mr.start(), mr.end());
        }
        s.close();
        if(count==1)
        {
         System.out.printf("amazon.txt file data found "); 
        }
        if(count2==1)
        {
         System.out.printf("amazoncomp.txt file data found "); 
        }
    }
}

No comments:

Post a Comment