Q:

Word Count in Java giving wrong output

I am new to Java.  
I have written a code to count the occurrence of a particular word from a file.  The word to be counted is asked from the user.  I wrote two codes.  The first code runs properly and the count is correct.  Whereas in the second code, the count is less.  I am unable to figure out the reason for this.  Can someone help me find the flaw in the second code? 
Paragraph that is read from the file and the two codes are provided below.  
Paragraph : 
In word processing and desktop publishing, a hard return or paragraph break indicates a new paragraph, to be distinguished from the soft return at the end of a line internal to a paragraph.  This distinction allows word wrap to automatically re-flow text as it is edited, without losing paragraph breaks.  The software may apply vertical whitespace or indenting at paragraph breaks, depending on the selected style. 
How such documented are actually stored depends on the file format.  For example, HTML uses the  tag as a paragraph container.  In plaintext files, there are two common formats.  Pre-formatted text will have a newline at the end of every physical line, and two newlines at the end of a paragraph, creating a blank line.  An alternative is to only put newlines at the end of each paragraph, and leave word wrapping up to the application that displays or processes the text (if it is even necessary). 
Code 1 : Gives correct output
package prac3;

import java.io. BufferedReader;
import java.io. FileNotFoundException;
import java.io. FileReader;
import java.io. IOException;
import java.util. Scanner;

public class FromFile {

    private String word;

    FromFile() {
    }

    int Count(String word1) throws IOException {
        this.word = word1;
        String abc;
        int count = 0, total = 0;
        try {
            BufferedReader in = new BufferedReader(
                    new FileReader(
                            "C:\\Documents and Settings\\Administrator. EGOVPC79\\Desktop\\file.txt"));

            while ((abc = in.readLine()) ! = null) {
                String abc1 = abc;
                Scanner s = new Scanner(abc1);
                while (s.hasNext()) {
                    total++;
                    if (s.next().equals(word)) {
                        count++;
                    }
                }
            }
            in.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

        System.out.println("total" + total);
        return count;
    }

    public static void main(String[] args) throws IOException {
        FromFile obj = new FromFile();
        String word;
        Scanner abc = new Scanner(System.in);
        System.out.println("Enter the word you want to count");
        word = abc.nextLine();
        int count = obj. Count(word);
        System.out.println("The occurence is :" + count);

    }
}

Code 2 : This gives incorrect output.  
package prac3_2;

import java.io. BufferedReader;
import java.io. FileReader;
import java.io. IOException;
import java.util. Scanner;

public class File {

    private String word;
    private String abc1;

    File() throws IOException {
        String abc;
        BufferedReader in = new BufferedReader(
                new FileReader(
                        "C:\\Documents and Settings\\Administrator. EGOVPC79\\Desktop\\file.txt"));
        while ((abc = in.readLine()) ! = null) {
            abc1 = abc;
            System.out.println(abc1);
        }
        in.close();
    }

    int Count(String word1) {
        this.word = word1;
        int count = 0, total = 0;
        Scanner s = new Scanner(abc1);
        while (s.hasNext()) {
            total++;
            if (s.next().equals(word)) {
                count++;
            }
        }
        System.out.println("total" + total);
        return count;
    }

    public static void main(String[] args) throws IOException {
        File obj = new File();
        String word;
        Scanner abc = new Scanner(System.in);
        System.out.println("Enter the word you want to count");
        word = abc.nextLine();
        int count = obj. Count(word);
        System.out.println("The occurence is :" + count);
    }
}

A:

Problem is abc1 does not have all the text and when counting, it counts supplied word only in last line it read (stored in abc1)
Using StringBuilder when reading file,append each line which is reading the file will make the count logic work. 
private StringBuilder abc1 = new StringBuilder();
....
....
 abc1.append(abc);
...
...
Scanner s = new Scanner(abc1.toString()); 

This will read entire text and scan for word

