Searching For A Word In Text File

Apr 17, 2014

I'm creating this small JAVA programme thats checks for a word in the dictionary but when I run it I get an error

"Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at spellChecker.project1.SpellChecker.main(SpellCheck er.java:10)"

This is my code:

package spellChecker.project1;
import java.io.FileReader;
import java.util.Scanner;
 public class SpellChecker{
public static void main(String[] args){ 
String myFileName = "/Users/Stalin/Desktop/dictionary.txt";

[Code] ....

View Replies


ADVERTISEMENT

AutoCorrect / Replace A Word That Is Similar To A Word In File Text

Mar 13, 2015

The intentions of this program is to prompt a user to enter a file name, and then reads the file. The program will prompt the user to enter a word that needs to be corrected. So lets say I have a text file containing "My name is OP and I Like goind to the Park!" I want to change "goind" to "going",

Now, my second method "isSimilar" executes a similar word with more than one same letter and same length, but I dont know how to execute that whole thing in my third method "correctThisLine" . How I can call that isSimilar method and read in that text file and change that word into that?

import java.util.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class WahidMuhammadA3Q2{
String fileName = "AutoCorrectMe.txt";
public static void main (String [] args){

[Code] ....

View Replies View Related

String Searching For A Word

Mar 25, 2015

I'm very new to Java, and I'm writing a code to search a string to see how many times the word "dog" is found in it. I'm not sure if this is error-free or the most efficient, but I'd like to keep it simple.

public void run()
{
 
String input = new String("The Dogman was no ordinary dog, nor man, but rather a peculiar dog-like man who barked like a dog, and panted like a dog, he even ate like a dog. He owned a dog named Doglips, and interestingly enough, his favorite food was hotdogs.");
 
println(input);
int index = -1;
int count = 0;
print("Counting dogs:");
inputarray = input.split(" ");
 
[Code] .....

View Replies View Related

Search For Certain Word In Text File

Mar 31, 2014

I need a java code to search a certain word from the text file. the word that i want to search is in other text file. and finally the output will print the result in the new text file. for the example the text file name data.txt and the word list in the wordlist.txt and the output will print filter.txt.

View Replies View Related

How To Save A Word In A Text File

Apr 19, 2014

This part of the code searches for every word in the text file and saves it to an ArrayList. It searches for the word if its valid of not.How can I offer a list of similar words when the word that the user inputs is not in the dictionary. Also I want it to prompt the user to accept the word or enter a replacement that gets saved in the dictionary.

package spellChecker.project1;
 
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
 
[code]....

View Replies View Related

Searching For Any Entered Text In A Directory Of Multiple Scanned PDF Files

Mar 31, 2015

Within tomcat "webapps" directory, have lots of scanned PDF files (size in KB and MB).Using Java and JSP, I want to search for any user entered text in these scanned PDF files.The result must display the name of those PDF files which has that entered text.

View Replies View Related

Searching Directories Recursively For File

May 8, 2015

I have a case: i have to make fast searching of a file in to all file systems(Linux or Windows). I use search directories recursively for file. Is there a quick way?

View Replies View Related

Searching Array - Read From A File That Is List Of Songs

Oct 10, 2014

I have an assignment for my intro class that requires me to read from a file that is a list of songs, their artists, and the year they were released. As seen below, a print line statement prompts the user to enter an artist name, and then it uses a buffered reader to gain input, and then it is supposed to match that input.I realize that this is not a complete statement, but I'm mostly concerned with getting the .indexOf statement to work.Currently it only returns the first object in the array.

for(int i = 0; i < song.length; i++) {
System.out.println("Enter an Artist name");
String input1 = kb.readLine();
if (song[i].getArtist().indexOf(input1) > -1) {
/*tried changing -1 to -2. When I do, it returns the
first array entry, regardless of what I input*/
System.out.println(song[i].toString());
}
}

View Replies View Related

Searching TXT File For A Specific Keyword And Output Whole Line

Feb 12, 2014

I need to search a txt file for a specific keyword and then output all the lines that contain that keyword. Right now I I think I have my search done but I don't know how I would print the whole line.

TextIO.readFile("xxx.txt");
String search;
String word;
int count=0;
TextIO.put("Please enter your search word: ");
search = TextIO.getln();
while (!TextIO.eof()) {
word = TextIO.getln();
count = count+1;
if (search.equalsIgnoreCase(word)==true){
TextIO.put(count + "-");
TextIO.put(word);

Right now it doesnt even let me enter in any values for the search. Not sure what I've done wrong..

View Replies View Related

Scan Text And Add Each Word Alphabetical Listing?

Mar 4, 2014

I'm scanning my text and I want to add them into array list, but it is not easy. I want each word store from arrayList of a to z which is arrayList size is 26. Example:

arrayList a store string array of: an, and, apple, ...

arrayList b store string array of: be, become, became.....
.
arrayList z store string array of: zero, zone...

In my class, I create:

private static ArrayList<String[]> words = new ArrayList<String[]>(26); // to store all words

In main, I do while loop to get each words and store in words array,
 
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Scanner;
public class BinaryTree {

[code]...

View Replies View Related

Text Files And Word Processing Software

Sep 1, 2007

Why is it simple for a word processing software (one that reads number of words, words greater that x characters etc) to deal with text file(.txt) and not with a doc file (.doc) file?? Is there any special requirements or what are the points taken into consideration while developing the software for a .doc file?

View Replies View Related

Extracting Numbers In Word Format From A String Of Text

Aug 7, 2014

I am trying to do is extract numbers that are in word format in a long String, i.e. a song, and return each of their numerical values, in order to add them all up. So I'd like to calculate the sum of all of the numbers in the text. This has to work for any piece of text and for all numbers up to a trillion.

So I broke the string down into tokens and stored them in a String []. And I divided up the possible numbers in word format into:

LARGEST: thousand, million, billion, trillion
HUNDRED: hundred
TENS: twenty, thirty, forty, fifty, sixty, seventy, eighty, ninety
UNITS: one, two, three, four, five, six, seven, eight, nine
SPECIALS: ten, eleven, twelve, thirteen, fourteen, fifteen, sixteen, seventeen, eighteen, nineteen

I believe that these are the only words that it will need to recognize. I began reading the tokenized string from right to left and then when I came across a unit, special or tens as the first number I hit, I would then set it's numerical value and check if the word before was also a number and whether to add or multiply etc. i.e. First number hit is a two, if the number before is sixty, then I would just add it to sixty and check the word before that and so on.

However, when implementing it, it seems like an extremely long way around it. How I could implement this in a swifter manner? An example of it working would be:

"Nine Million rockets turned Three times and met Twenty Two Aliens", it would extract, Twenty Two as 2, then 20 = 22, then extract Three as 3, and then Nine Million as 1,000,000 x 9 = 9,000,000

9,000,000 + 22 + 3 = 9,000,025

View Replies View Related

String In Java - Search Text On Document For A Word

Feb 5, 2014

Consider in a Document if a String " Hello" is Encoded and stored as "XYZAB"

I want to search the text on document for a word "Hello" and Replace the word with "HelloWorld"

The Program will encrypt the word "Hello" and Search the file then return the encrypted code as "XYZAB" Found

Now i have to replace the word "Hello" with "HelloWorld" in encrypted form so that the Letter "XYZABEFGHI" is replace in the place of Hello where "World" is encoded as "EFGHI"

Now the Problem is If there is more number of occurrence of the word "Helloworld" exist in the file... How can i Replace only one particular occurrence What can be done to select the particular occurrence.

I have attached my java program for Encryption along with this mail for your ease of use.

View Replies View Related

How To Make A Text File Only Use Lines In A Text File Beginning With A Certain Letter

Mar 15, 2015

I have a program that reads lines of text, but some of the lines of text aren't applicable and break the program. I'd like to put a letter in front of the lines in the .txt file I want to use, such as a #.

I need to make an if loop that'll check for the first letter on the line being #, and use the line in the program if true and skip if false. I'm guessing a boolean variable would be useful here to be true or false depending on the presence of #, but I don't know how to only read the first letter of each line, how can I do this?

View Replies View Related

Pickup Selected Text File And Read Line By Line And Output Text Into Visual Text Pane

Dec 12, 2014

I am checking how to do following task.

01. pickup the selected text file and read the line by line and output the text in to visual text pane.

what i did:.

01. I wrote code that read the text file and output in to jave console/ also some of the interface.

the code read txt file:

Java Code:

String fileName = "C:/Users/lakshan/Desktop/lawyer.txt";
File textFile = new File(fileName);
Scanner in = new Scanner (textFile);
while(in.hasNextLine()){

[code]....

so it will read any text file dynamically and output to the text pane in interface. I think scanner code must be execute after the select the file from the browser and set the scanned result in to variable. then later out put the var as string in some jswing component?

View Replies View Related

Adding Records To A File Then Searching That File For Records

Jan 30, 2015

The assignment is to create a program that accepts entries from a user for 3 variables then saves the data to a file. There are other programs that use the file created. One program displays the non-default records. The next program allows the user to enter the id for the employee and displays the first and last name for that id number. The last program allows the user to enter a first name. It then displays all id numbers and last names for records with that first name.

Given the above situation, I am stuck on creating the first program. I can make the text file and write the information to it. However, when the file is created, a space is placed in between each entry for some reason. I cannot figure out how to get rid of this space so that I can display the appropriate records for the remaining programs. Below is the code and a view of my problem.

import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.file.*;
import java.io.*;
import static java.nio.file.StandardOpenOption.*;
import java.util.*;
public class WriteEmployeeList {

[Code] .....

The values for nameFormat and lnameFormat are 10 spaces. This is how the book told me to make sure everything is uniform and searchable. The file contents look like this when viewed in notepad.

000, ,
000, ,
000, ,
000, ,
000, ,

123,Justin,Slacum
124,Justin,Jones
125,James,Smithy
126,Jake,Flabernathy
127,John,Panakosfskee
128,SuzetteMae,Ginther

000, ,
000, ,
000, ,
000, ,
000, ,
000, ,
000, ,

View Replies View Related

Check For A Word That Is Contained In A File?

Apr 17, 2014

I need the user to enter the name of a file and check if the word is contained in the dictionary file.

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Scanner;
public class SpellChecker{
public static void main(String[] args){

[code]....

I need to read the file and separate the words and save them in a collection after read another file and search each line for one of the words in the collection.

View Replies View Related

User Enter A File On Text Field And Display Its Hex Representation In Text Area

Apr 17, 2015

I'm supposed to write a GUI application letting the user enter a file on the text field and display its hex representation in a text area and vice versa.

Here's my code:

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package hexconvertor;
import java.util.*;
import java.io.*;
public class HexConvertor extends javax.swing.JFrame {

[Code] .....

It's not doing anything, I don't understand why.

View Replies View Related

Binary Tree - Storing Each Word As String And Int Frequency For Each Time Word Occurs

Apr 27, 2015

I have built a binary tree, from a file. In each node, I am storing each word as a string, and an int frequency for each time the word occurs. For the assignment, I need to find how many words occur only once in the file. I wrote the program, but for some reason I am getting a number different from what my professor is expecting.

As far as I know, this file has loaded into the tree correctly, because all of my other answers in the assignment are correct. What am I doing wrong?

public void findUnique() {
System.out.println("There are " + findUniqueWords(root, 0) + " unique words.");
}
private int findUniqueWords(Node subTree, int uniqueCount) {
// Base Case: At the end of the branch
if(subTree == null){
return uniqueCount;

[Code] ....

View Replies View Related

I/O / Streams :: How To Use Java To Generate Word Document From A Word Template

Aug 19, 2014

I am looking for java codes to generate a word document based on a word template, basically, I have a word template created and in my local path, the template has a proper format with some fields which will be filled in after java codes ran. The java codes will fetch one record from a table, and open the word template and then fill the fields in the word template, and created a new word document and save it in another folder.

I found this example: [URL] which is similar except it uses xml template instead of word template, how to make it work to change the template from xml to word (docx) template?

View Replies View Related

Read A Text File And Split The Text Into Tokens

Feb 2, 2014

I am trying to read a text file into Java and split the text into tokens. Eventually I want to be able to count the number of instances of a specific word. However, at this point, when I run the file, all I get is the location of the file rather than the text in the file.

import java.util.*;
import java.io.*;
public class textTest3 {
/**
* Prints the number of words in a given file
*
* @param args
* @throws IOException
*/

[Code]...

View Replies View Related

Program To Count Character Word And Line From A File?

Dec 27, 2014

public static void main(String[] args) throws FileNotFoundException, IOException{
// TODO code application logic here
FileReader fr = new FileReader("gautam.txt");
BufferedReader br = new BufferedReader(fr);
  int line = 0;
int word = 0;
int character = 0;
String s;
while((s=br.readLine())!=null)

[code]...

how to count the character from file

View Replies View Related

Split String From Given File Find Word Position

May 4, 2014

I have included split() to put a string read from a given file into indexed array. Looking for a word position (not char position number in addition to the line number I have already written. Line number works fine, however word position isn't quite right.Below is my code:

import java.io.*;
public class Word implements Comparable, TreeComparable{
String word;
int count;
int wordpos;
ObjectList lines;
private SuperOutput so;

[code]....

View Replies View Related

Telephone Number - Write To A File Every Possible Seven-letter Word Combination

Nov 23, 2014

I am having some trouble with this program. The assignment is to write a program, given a seven-digit phone number, uses a PrintStream object to write to a file every possible seven-letter word combination that corresponds to that number. I have to avoid using 0 or 1. Here is my code.

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Scanner;
public class TelephoneGenerator
{
String phoneNumber;
char numberLetters[][] = {

[Code] ....

I am getting an error dealing with the main class.

View Replies View Related

Read Line From File And Save First String As Word And Remaining As Meaning

Jul 6, 2014

I have written the code to read the line from file and save first string as word and and remaining string as meaning..

E.g.: innovation a new method, idea, product, etc.

word = innovation

meaning = a new method, idea, product, etc.

In my code there is no error and have a mistake what it is means first assigning word is ok and while saving meaning ..it saves like

{
a a new a new method } like that

Java Code:

import java.io.BufferedReader;
import java.io.FileReader;
public class Dil{
public static void main(String[] arg)throws Exception
{
BufferedReader in;

[Code] ......

View Replies View Related

Output Contents Of Input File In Alphabetical Order One Word Per Line

Jun 22, 2014

I am having a lot of trouble with this lab. basically I have to make a text processor to read in code put it into a file and output the contents of the input file in alphabetical order one word per line. I have to reference the string varaibles input_filename and output_filename.

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
import java.io.File;
public class TextProcessor {

[Code] ....

these are the guidelines to said lab:

1. In the main method define two Strings called input_filename and output_filename. I will be setting these Strings to my own file names for testing your code, so make sure you get these variable names correct, and that you use them properly in the following steps.
2. Read in the text contents of the file referenced by input_filename.
3. Split the contents of the input text into separate tokens, using whitespace as a delimiter.
4. Lower case the tokens.
5. OPTIONAL: remove punctuation
6. Alphabetize the tokens.
7. Using output_filename, write the alphabetized tokens to an output file, one token per line.
8. Be sure to close file streams - no resource leaks!
9. Use methods to separate functionality in your program where possible

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved