How do I compare these text files (aka spell check)

I'm having the hardest time figuring out how to get this spell check to work. Basically, I need to open the dictionary.txt file and then another file which will be spell checked. Ignoring case sensitivity, punctuation, and word endings (such as ly, ing, s). And then output to the user the words that were not found in the dictionary. Here is what I have so far (and it is very basic.... there is no attempt to compare yet since I don't know how to approach this). I only have it outputting to a JTextArea what is opened minus punctuation and upper case....
import java.util.Scanner;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
//  Created Sept 4, 2004
*   @version 1.0
*   This program will store dictionary.txt to a String array and
*   open another text file to be specified by the user of the program.
*   As the scanner proceeds through the document, it will spell check
*   and output any (case insensitive) words not found in the
*   dictionary.txt file.
public class Spell extends JFrame {
    /** Area to place the individual words in the file */
    JTextArea outputDictionary, outputWord;
*  Constructor for the class.  Sets up the swing components.
*  Prompts the user for the files to be processed.  Then invokes
*  the process method to actually do the work.
public Spell() {
     // A JTextArea is used to display each word found in the file.
     outputDictionary=new JTextArea("Dictionary List\n\n");
     add (new JScrollPane(outputDictionary));
     //Set the size to 300 wide by 600 pixels high
     setSize(300,600);
     setVisible(true);
        outputWord=new JTextArea("Opened Document\n\n");
        add (new JScrollPane(outputWord));
        setSize(300,600);
        setVisible(true);
    //Prompts user for the dictionary.txt file
    JFileChooser dictionary = new JFileChooser();
    int returnVal = dictionary.showOpenDialog(this);
     if  (returnVal == JFileChooser.APPROVE_OPTION) {
          storeDictionary(dictionary.getSelectedFile());
    //Prompt user to open file to be checked          
    JFileChooser word = new JFileChooser();
    int returnVal2 = word.showOpenDialog(this);
        if (returnVal2 == JFileChooser.APPROVE_OPTION){
            storeOpenFile(word.getSelectedFile());
public void storeDictionary(File dictionaryFile) {
     String dictionary="";
     Scanner scanner=null;
    try {
        // Delimiters specifiy where to parse tokens in a scanner
       scanner = new Scanner(dictionaryFile).useDelimiter("\\s*[\\p{Punct}*\\s+]\\s*");
    catch (FileNotFoundException fnfe) {
        JOptionPane.showMessageDialog(this,"Could not open the file");
       System.exit(-1);
     while (scanner.hasNext()) {         
          dictionary=scanner.next();
          if (!dictionary.equals(""))
             outputDictionary.append(dictionary.toLowerCase()+"\n");
        System.out.println("Thank you, your dictionary is stored.");
public void storeOpenFile(File openFile){
    String word="";
    Scanner scanner2 = null;
    try {
        // Delimiters specifiy where to parse tokens in a scanner
       scanner2 = new Scanner(openFile).useDelimiter("\\s*[\\p{Punct}*\\s+]\\s*");
    catch (FileNotFoundException fnfe) {
        JOptionPane.showMessageDialog(this,"Could not open the file");
       System.exit(-1);
    //stores the words in the opened text file in a String array
     while (scanner2.hasNext()) {         
          word=scanner2.next();
             if(!word.equals(""))
                    outputWord.append(word.toLowerCase()+"\n");
    System.out.println("Thanks, your file has successfully been opened.");
public static void main(String args[]) {
   Spell spellck = new Spell();
   spellck.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

Yes, he actually recommends us to use java 1.5. I have revised my code to read into a TreeSet from the dictionary.txt, but I keep getting the following error when I compile:
Note: C:\Jwork\spell1.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Finished spell1.
Also, when I execute, nothing happens. It looks like it is going to try to do something, but the "open" dialog box never opens and no errors pop up. It just sits there executing. Any suggestions??
here is the code:
import java.util.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
//  Created Sept 4, 2004
*   @version 1.0
*   This program will store dictionary.txt to a String array and
*   open another text file to be specified by the user of the program.
*   As the scanner proceeds through the document, it will spell check
*   and output any (case insensitive) words not found in the
*   dictionary.txt file.
public class spell1 extends JFrame{
    JTextArea output = new JTextArea(500,500);
    Set dict = new TreeSet();
    Set file = new HashSet();
    public spell1(){
    Set dict = new TreeSet();
    Set file = new HashSet();
    //Prompts user for the dictionary.txt file
    JFileChooser dictionary = new JFileChooser();
    JFileChooser wordFiles = new JFileChooser();
    int returnVal = dictionary.showOpenDialog(this);
     if (returnVal == JFileChooser.APPROVE_OPTION) {
     storeDictionary(dictionary.getSelectedFile());
    int returnVal2 = wordFiles.showOpenDialog(this);
        if (returnVal2 == JFileChooser.APPROVE_OPTION){
            storeFile(wordFiles.getSelectedFile());
    public void storeDictionary(File dictionaryFile){
        String dictionary="";
     Scanner scanner=null;
    try {
       // Delimiters specifiy where to parse tokens in a scanner
       scanner = new Scanner(dictionaryFile).useDelimiter("\\s*[\\p{Punct}*\\s+]\\s*");
    catch (FileNotFoundException fnfe) {
        JOptionPane.showMessageDialog(this,"Could not open the file");
       System.exit(-1);
     while (scanner.hasNext()) {
          if (!dictionary.equals(""))
             dict.add(scanner.next());
        System.out.println("Thank you, your dictionary is stored.");
    public void storeFile(File wordFile){
        String word="";
        Scanner scanner2=null;
    try{
        scanner2 = new Scanner(wordFile).useDelimiter("\\s*[\\p{Punct}*\\s+]\\s*");
    catch (FileNotFoundException fnfe){
        JOptionPane.showMessageDialog(this,"Could not open the file");
        System.exit(-1);
        while(scanner2.hasNext()){
            if(!word.equals(""))
                file.add(scanner2.next());
    public static void main(String args[]){
        spell1 spellck = new spell1();
        spellck.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

Similar Messages

  • Comparing two text files in a UNIX using shell programming

    Hi All,
    Sorry for posting a UNIX shell query on Database forums.
    I want to compare two text files using shell programming. The two text files are actually Business Objects output extracted in a text format. The two output files are not in a tabular format and are no way similar in looking. I want to take one file e.g. file1 as an input file and compare each line of file1 with the other file e.g. file2. During comparison I want to extract the differences found in another file and if possible the similar data as well.
    Below is how the files will look like
    File 1:
    BILL1000000 1111251 122222
    RMG1A2 023425100000000010001 11135 102650111100
    UHL1 *6999999* *454540001* Weekly *000*
    0544424556895PS DATA 01MPS100000/03 MR A A PERTH UTL1234567893106923455053106900000010000005
    File 2:
    AUTO
    APPLICATION=STARTPOINT
    START
    PROCESSING DATE=01012011
    1598301270320099TEST C E 00000031615 123456
    7854301276140499TES P 00000062943 234567
    UHL1 *6999999* *454540001* Weekly *000*
    5569931233333499/123456789 00000013396 345678
    4471931233333499ER K J 00000031835123456789012456789
    33652931233333499E J L 00000034729123456789012567890
    45783123333349921/123456789 00000039080 678901
    1452931233333499T R 00000040678123456789012789012
    59689312333334994/987654321 00000048614 890123
    4112931233333499/987654321 00000060631 901234
    1236931217836899 K S 00000043704 012345
    END
    As you can see above the file are not at all matching except for one record UHL1, but its just an example. As an output I would like to have a third file containing all these records, highlighting the differences, and a fourth file where in only the matched records should get populated.
    Please post any useful scripts related to the above scenario.
    Many Thanks.
    Edited by: 848265 on 06-Apr-2011 04:13

    Hi;
    For your issue i suggest close your thread here as changing thread status to answere and move it to Forum Home » Linux which you can get more quick response
    Regard
    Helios

  • Compare 2 text files

    Hello guys ... I want to compare two text files and then print line if the files are identical or not. What I have here is comparing linie by line and is printing after each line. How can compare all the text and after that just print if all the file is the same or not
    import java.io.BufferedReader;
    import java.io.FileReader;
    public class compare
         public compare() throws Exception
              BufferedReader fx = new BufferedReader(new FileReader("1.txt"),1024);
              BufferedReader sx = new BufferedReader(new FileReader("2.txt"),1024);
    String s;
    String y;
    while ((s=fx.readLine())!=null)
    if ((y=sx.readLine()).equals (s))
         System.out.println("These line is the Same");
    else
             System.out.println("These line is different");
    sx.close();
    fx.close();
         public static void main(String[] args) throws Exception
                 new compare();
    }Thanks

    adi77 wrote:
    do you have any idee what could be the problem?Yes, all sorts of things.
    Don't compare Strings with ==
    sx.readLine() == fx.readLine()Use equals() instead
    sx.readLine().equals(fx.readLine())Do you know what the word 'different' means?
    if (sx.readLine() == fx.readLine())
            different = true;If so, then why do you set 'different' to true when the lines are the same?
    if (sx.readLine() != fx.readLine())
         System.out.println("This file is identical");You've already read all the lines in the files, why are you reading again? Use the boolean you set in your loop!
    if (different)
        System.out.println("File is different");

  • How do I get a text file from Photoshop  to work in the main sequence in pp?

    How do I get a text file to work properly in the master sequence. I moved it from Photoshop, which I learned to do from a tutorial, but when I move the animated text sequence to the master, it either isnt running, or it is scaled way too big. How do I get it to run in the main sequence?

    "Wont Work Here" !  Does not mean much.
    Are you having an audio or a video issue? 
    Looks like no video clip on the video layer above that section of audio.
    I am teaching myself this stuff completely on the fly
    I suggest you do the Basic Tutorials ( Adobe TV for example) in both Premiere Pro and PhotoShop.
    You need to be competent in the basics and fundamentals of these apps and that will also help you describe and discuss the issues.   Check the 'Products on this site....
    Adobe TV

  • How to create PDF from text file with specific layout?

    I wanted to create the pdf from text file in specific layout - Landscape orientation and JIS B3 Page size while at Adobe Acrobat Pro.
    In past, I could do a right click on a text file (desktop area) and select print to print out the document into .pdf BUT only if I set the Adobe PDF to Landscape and JIS B3 Page size BEFORE.  And I could only do 15 text documents at once.
    I wanted to see if I could do the create the pdf from text file with specific layout in Adobe Acrobat without having to go to Control Panel to preset the Adobe PDF to specific layout at every time.   I would have to set Adobe PDF back to normal layout after I'm done with these pdf print outs.  I do lots of pdfs in normal layout.  Sometimes I would forget to do that.
    So, How do I do that?

    No such luck.  It would output the contents in letter size even in JIS B3 Page layout at MS word. 
    Is there a script or action where I could set the orientation and page size before creating PDF on these text files?

  • How can i feed a text file into a Hashtable?

    Hi,
    im working on my third year project, im new to java and am struggling a little with writing the code.
    I need to feed a text file into my program and insert it into a hashtable. I presume i'll be using an input stream to feed the file in, how do i go about placin the text file into a hashtable??
    please help!

    ok, so im trying to code an authorship attribution
    program. the first part of the program need to
    compare a text file A (list of words), with another
    two text files B and C. Compare how? Do you want to know how many times certain words from list A appear in files B and C?
    The words in list A will first be compared to those
    in list B and than list C. I was wondering if there
    was a way of inserting file A,A Map is a list of key/value pairs, so what do you mean by inserting here? What are you inserting? What would the keys and values here be?
    followed by B,
    comparing the two files.....than inserting file C and
    comparing it with A??
    Does this make sense??Not quite, but it might just be me.

  • How to scan/ read a text file, pick up only lines you wanted.

    I'm new to Labview, I trying to wire a VI which can read a text file
    example below:
    Example: My Text File:
    1 abcd
    2 efgh
    8 aaaa
    1 uuuu
    and pick out only any line which start with number 1 (i.e 1 abcd)
    then output these 2 lines out to a a new text file?
    Thanks,
    Palmtree

    Hi,
    How do you creat your text files? Depending on the programm, there is added characters in the beginning and at the and of the file. So here you will find a VI to creat "raw" text files.
    To debug your VIs, use the probs and breakpoints, so you can solve the problem by your self or give an more accurate description of it.
    There is also the VI that read a integer and two strings  (%d %s %s)
    Attachments:
    creat text file.vi ‏9 KB
    read_from_file.vi ‏14 KB

  • How do I open a text file to sort using bubble sort?

    Hi,
    I have a text file, which is a list of #'s.. ex)
    0.001121
    0.313313
    0.001334
    how do you open a text file and read a list? I have the bubble sort code which sorts.. thanks

    I wrote this, but am getting a couple errors:
    import java.util.*;
    import java.io.*;
    public class sort
         public static void main(String[] args)
              String fileName = "numsRandom1024.txt";
              Scanner fromFile = null;
              int index = 0;
              double[] a = new double[1024];Don't use double. You should use something that implements Comparable, like java.lang.Double.
              try
                   fromFile = new Scanner(new File(fileName));
              catch (FileNotFoundException e)
    System.out.println("Error opening the file " +
    " + fileName);
                   System.exit(0);
              while (fromFile.hasNextLine())
                   String line = fromFile.nextLine();
                   a[index] = Double.parseDouble(line);Don't parse to a double, create a java.lang.Double instead.
                   System.out.println(a[index]);
                   index++;
              fromFile.close();
              bubbleSort( a, 0, a.length-1 );No. Don't use a.length-1: from index to a.length-1 all values will be null (if you use Double's). Call it like this:bubbleSort(a, 0, index);
    public static <T extends Comparable<? super T>> void
    d bubbleSort( T[] a, int first, int last )
              for(int counter = 0 ; counter < 1024 ; counter++)
    for(int counter2 = 1 ; counter2 < (1024-counter) ;
    ) ; counter2++)Don't let those counter loop to 1024. The max should be last .
                        if(a[counter2-1] > a[counter2])No. Use the compareTo(...) method:if(a[counter2-1].compareTo(a[counter2]) > 0) {
                             double temp = a[counter2];No, your array contains Comparable's of type T, use that type then:T temp = a[counter2];
    // ...Good luck.

  • How to include non-photo text files when burning a DVD-RW

    I'm using Photoshop Elements 3.0.1 on Windows XP Service Pack 2.
    I want to include a couple of text (TXT) files on a DVD-RW disc that I'm going to burn my photos to. The text files will contain a chronicle of the trip on which I took the photos.
    I can't figure out how to get Photoshop Elements (PSE) to let me include these text files. Is there a way to do that in PSE? It seems to only allow you to work with photo files.
    As a work-around, I tried first burning the text files to the disc using Nero and not finalizing the disc. I then tried to use PSE's burn command to add the photos, but PSE objected that the disc was not empty and asked me if I wanted to erase its contents. When I said "No", it asked me to insert a different disc. So apparently PSE will only work with an empty disc or a partially-full disc that you are willing to erase first.
    Help!
    Thanks.
    Steve Westfall

    Ward,
    I didn't try burning the photos first and then burning the text files with Nero, because I read elsewhere in the forum that PSE has the nasty habit of always finalizing the disc when it finishes its burning session, which means you couldn't add anything to it in a subsequent burning session. However, I haven't verified that. I'll have to try it.
    The work-around that I finally came up with and successfully used was basically your second option. I used the export command to export the pictures that I want to a directory, and then used Nero to burn those pictures and anything else I want to the disc.
    Still, it seems like there ought to be a way to get PSE to include files other than photos.
    Thanks for your input.
    Steve

  • How to read a whole text file into a pl/sql variable?

    Hi, I need to read an entire text file--which actually contains an email message extracted from a content management system-- into a variable in a pl/sql package, so I can insert some information from the database and then send the email. I want to read the whole text file in one shot, not just one line at a time. Shoud I use Utl_File.Get_Raw or is there another more appropriate way to do this?

    how to read a whole text file into a pl/sql variable?
    your_clob_variable := dbms_xslprocessor.read2clob('YOUR_DIRECTORY','YOUR_FILE');
    ....

  • How to read the whole text file lines using FTP adapter

    Hi all,
    How to read the whole text file lines when error occured middle of the text file reading.
    after it is not reading the remaining lines . how to read the whole text file using FTP adapter
    pls can you help me

    Yes there is you need to use the uniqueMessageSeparator property. Have a look at the following link for its implementation.
    http://download-west.oracle.com/docs/cd/B31017_01/integrate.1013/b28994/adptr_file.htm#CIACDAAC
    cheers
    James

  • Compare two text file

    i am comparing two text file by checking occurance of a line in file 1 by comparing it with each line in file 2(not line by line)
    i have to print in 3rd text file as difference
    please see my progrm and tell me modification required
    package comp.vnet.comparator;
    import java.io.*;
    import comp.vnet.comparator.NewFile;
    class FileComparator {
         public static void main(String[] args) throws IOException{
              String file1,file2,String1,String2;
              BufferedReader br1,br2;
              int fileCount1=0;
              int fileCount2=0;
              br1= new BufferedReader(new InputStreamReader (System.in));
              // File file = new File ("output.txt");
              FileWriter fstream = new FileWriter("out.txt");
              // FileOutputStream fo = new FileOutputStream("E:/Filecomparator/FileComparator/output.txt");
              System.out.println("Enter First file name");
              file1="b.txt";
              //file1=br1.readLine();
              System.out.println("Enter Second file name");
              file2="a.txt";
              //file2=br2.readLine();
              NewFile nf= new NewFile();
              br1=nf.creatingFile(file1);
              br2=nf.creatingFile(file2);
    while ((String1= br1.readLine()) != null) {
         fileCount1++;
    while ((String2= br2.readLine()) != null) {
         fileCount2++;
    System.out.println("fileCount1+ : " + fileCount1);
    System.out.println("fileCount2+ : " + fileCount1);
    br1=nf.creatingFile(file1);
    BufferedWriter out = new BufferedWriter(fstream);
    for(int i=0;i<=fileCount1;i++)
         br2=nf.creatingFile(file2);
         String1=br1.readLine();
         for(int j=0;j<fileCount2;j++)
                   String2=br2.readLine();
                        if ( String1.equals (String2) ) {
                             System.out.println("the line is equal");
                        else{
                        out.write(String1);
                             System.out.println(String1);
    out.close();
    br1.close();
    br2.close();
              }

    thanks alot for that reply
    but there is some error
    pleasse send me a nice reply

  • How to write data to text file using external tables

    can anybody tell how to write data to text file using external tables concept?

    Hi,
    Using external table u can load the data in your local table in database,
    then using your local db table and UTL_FILE pacakge u can wrrite data to text file
    external table
    ~~~~~~~~~~~
    http://download-east.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_7002.htm#i2153251
    UTL_FILE
    ~~~~~~~~~
    http://download-east.oracle.com/docs/cd/B19306_01/appdev.102/b14258/u_file.htm#sthref14093
    Message was edited by:
    Nicloei W
    Message was edited by:
    Nicloei W

  • How to append paragraph in text file of TextEdit application using applescript

    how to append paragraph in text file of TextEdit application using applescript and how do i save as different location.

    christian erlinger wrote:
    When you want to print out an escape character in java (java is doing the work in client_text_io ), you'd need to escape it.
    client_text_io.put_line(out_file, replace('your_path', '\','\\'));cheersI tried replacing \ with double slash but it just printed double slash in the bat file. again the path was broken into two lines.
    file output
    chdir C:\\DOCUME~1\
    195969\\LOCALS~1\\Temp\
    Edited by: rivas on Mar 21, 2011 6:03 AM

  • How to create and read text file using LabVIEW 7.1 PDA module?

    How to create and read text file using LabVIEW 7.1 PDA module? I can not create a text file and read it.
    I attach my code here.
    Attachments:
    File_IO.vi ‏82 KB

    Well my acquisition code runs perfect. The problem is reading it. I can't seem to read my data no matter what I do. My data gets saved as a string using the array to string vi but I've read that the string to array vi (which I need to convert back to array to read my data) does not work on the pda. I'm using version 8.0. So I was trying to modify the program posted in this discussion so that it would save data from my DAQ. I did that but I still can't read the data after its saved. I really don't know what else to do. All I need to do is read the data on the pda itself. I can't understand why I'm having such a hard time doing that. I found a possible solution on another discussion that talks about parsing the strings because of the bug in the "string to array" vi. However, that lead me to another problem because for some reason, the array indicators or graphs don't function on the pda. When i build the program to the pda or emulator, the array indicators are faded out on the front panel as if the function is not valid. Does this kind of help give a better picture of what I'm trying to do. Simply read data back. Thanks.

Maybe you are looking for

  • Unable to connect to server on ipad mini to edit account info

    When I try to view terms and conditions to edit account info on ipad mini, the message unable to connect to server message pops up.  I am able to access internet however.

  • Query to find the number of main meter and its corresponding sub meter

    Hi Expert, I need to build a query to derieve the main meter & it corresponding sub meter in SAP system Please could you let me the table which i should join

  • Need info about CPU and HDD for Tecra 8200

    Hi Guys im new and have just bought the above laptop. However i want a faster CPU and bigger Harddrive (10GIG at the mo after 40 GIG if possible) and my CPU is Intel Pentium III 750MHZ. Please could someone point me in the right direction of where i

  • Imap in mail stopped working

    Mail stopped working and indicated fault with regard to IMAP settings. These have not been changed and always worked. The respective web and mobile interfaces work without issues.

  • Can't boot up from install disc

    Install disc shows on the desk top and in restart under system preferences but will not restart the Mac, I have also tried holding the "c" down on start up but nothing happens though I can hear the drive spinning. Is there some way I can get informat