Extracting Words From Text File
Jan 24, 2014
I have these sample strings in a text file : goldfish, fish, dish, filter and i need to extract them out with letters : "is" and need to print them out in another text file. Currently I am able to read the contents of the file but I am not able to print the same it in the new file.
public class Demo {
public static void main(String[] args) {
String filename = "a.txt";
try {
[code]....
View Replies
ADVERTISEMENT
Apr 9, 2015
java code for adding one text file into the zipped file without extracting It is possible in java code ?
View Replies
View Related
Apr 12, 2015
I am writing a program for my college class that does the following:
Reads a text file that consists of words from a-z. The content read from the file is displayed in the JTextArea, while the user can filter the search results based on what they input. For example, if the user enter's "a" then the JTextArea is updated with all words that start with the letter "a" only. Also the user can enter a substring or the whole word and the respective result will be only the words that match the user's input.
The Problem and question I have is what would be the best way to go about filtering a file of about 27,000 words based on user input. I tried using an arraylist but the problem is it took forever to update the JTextArea, which is not good. Also I am new to using JSwing so I may not be aware of a component that would make this easier.
Here is the code:
Note: the question lies within the actionPerformed method.
package source_code;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
[Code]...
View Replies
View Related
Apr 5, 2014
I have an assignment for college that involves placing randomly chosen words from a text file into a 2-d array. I have nearly completed ithowever I am having difficulty with a list of string type.What I have done so far is below,
import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;
import java.io.*;
import java.lang.Math;
[code]....
when I try to run an instance of the program(using BlueJ) I get an error saying there is a null pointer exception at line 35 which is wordsForGrid. add (puzzleWords.get(pos));
I am thinking that this is related to the fact that at this line in the loadWordsFromFile method List <String>words=new ArrayList<String>(); I could not create an empty list of string type, i.e List<String>words = new List<String>();
Is this correct? Or am I looking in the wrong place. The textfile I am using contains over 6000 words on a separate line for each if that makes any difference.
View Replies
View Related
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
Oct 16, 2014
java api that convert speech to text but complete english not predifined words only.
View Replies
View Related
Nov 9, 2014
So currently I am trying to use a JTextarea to display text and I then prompt users to type in certain words. I have a few problems that I have encountered. Firstly when I use setText and then if I say setText again after that it erases the previous text that was set. Ideally I want to set text once per line in my whenever a certain task is fulfilled. For example if the text says enter y/n, I want the program to go to the next line once I say y or n. Another problem of course is when I setEditable to true I can edit the whole textArea. I just want to be able to edit the line which I am currently at. Is there anything that I can use that mimics the ACM console program, or even the console down below in most IDE's where everything appears to be done line by line?
Also here is an example of what I am trying to do, along with comments:
Java Code:
console.setText("Math is good!");
console.setText("What is 2+2?: "); //using getText gets the whole line, I want
//everything checked after the colon. That is where the input will be
if(line==4){
console.setText("That is correct");
}
else {
console.setText("That is incorrect");
}
//previous text lines are overriden with new ones. I don't want that, nor do I want to be able to edit the
//whole JtextArea mh_sh_highlight_all('java');
A JtextArea is just not getting the job done.
View Replies
View Related
Sep 24, 2014
Well my code is supposed to ask for an input file and then (ex: input.txt), read the input file and create an output.txt file with the anagram for the words in the file. Also it should be displayed on the screen. However my code doesn't display the anagram on screen or the output file!
Heres is the code:
import java.io.*;
import java.lang.*;
import java.util.*;
/* This program will read a file given by the user, read the words within the file and determine anagrams of the given words. If the file that the user inputs is empty, then the program will output "The input file is empty."
* The program will read the file line by line, counting the total number of words read. If there are more than 50 words, "There are more than 50 words."
* will be printed, and the program will terminate. After each line is read, the words in the line will be separated,punctuation characters will be removed, and upper case characters will be switched to lower case.
* If any word is larger than 12 characters, that word will not be considered in the total amount of words in the file and it will not be sorted.
* After each word is read, the letters will be sorted and stored into an array containing each
* word's 'signature'. After all the words have been read, words will be printed to the output file on the same line based upon their signature.
*/
public class Anagram {
//Creating constants for maximum words in file and maximum chars in word
public static final int MAX_CHARS = 12;
public static final int MAX_WORDS = 50;
[Code] ....
View Replies
View Related
Apr 15, 2015
Write a menu driven program that either accepts words and their meanings, or displays the list of words in lexicographical order (i.e. as in a dictionary). When an entry is to be added to the dictionary you must first enter the word as one string, and then enter the meaning as separate string. Another requirement - from time to time words become obsolete. When this happens, such word must be removed from the dictionary.
Use the JOptionPane class to enter the information.
Use the concept of linked list to carryout this exercise. You will need at minimum the following classes:
- A WordMeaning class that hold the name of a word and its meaning.
- A WordMeaningNode class that creates the node of information and its link field.
- A WordList class that creates and maintain a linked list of words and their meanings.
- A Dictionary class that test your classes.
For the output, the program should produce two scrollable lists:
- The current list of words and their meanings.
- The list of the deleted words. You need not list the meanings, just the words.
So far, I have everything coded except for the remove method, and I am not sure how to code that. I coded the add method already, but now I don't know where to begin with the remove method in my WordList class. My classes are below.
WordMeaning Class:
public class WordMeaning {
String name;
String definition;
WordMeaning(String t, String d) {
name = t;
definition = d;
[Code] .....
View Replies
View Related
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
Nov 21, 2014
I have wrote this class who read from text line by line and save the words in fileOnTable.. Now i don't know what to read in ReadOffer to save the words in object offers and return this.. One more question.. What JUnit test can write for this code..?
package com.example.crazysellout.UserSide;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
[Code] ....
View Replies
View Related
Apr 15, 2014
I have been trying to get this method to work for a few hours now, for some reason I get an IndexOutOfBounds exception every time. Basically I am trying to read a txt file and add the words to an ArrayList as strings separated by a space .
private ArrayList<String> readLinesFromFile(BufferedReader inputFile) throws IOException
{
String value = null;
ArrayList<String> result = new ArrayList<String>();
while((value = inputFile.readLine()) != null){
String[] values = value.split(" ");
for (int i = 0; i < values.length; i++){
result.add(values[i]);
}
}
return result;
}
View Replies
View Related
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
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
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
Jul 3, 2014
example input (#federer #great #game )->
output : [federer] [great][game], [federer, game],[federer,great], [game,great], [federer, game,great]
View Replies
View Related
Aug 8, 2014
I am working on a card game and for lack of better terms, have royally screwed up my files. I do still have an executable jar that I would like to go back to if possible and try to redo what I messed up. What I was able to do was to use WinRAR and get ?encrypted? class files. Something that is obviously not editable. How can I go about converting these back to editable java files, if possible?
View Replies
View Related
Oct 13, 2014
Okay So I am creating an application but I'm not sure how to get certain parts of the string. I have read In a file as such:
*tp*|21394398437984|163600
*2*|AAA|1234567894561236|STOP|20140527|Success||Automated|DSPRN1234567
*2*|AAA|1234567894561237|STOP|20140527|Success||Automated|DPSRN1234568
*3*|2
I need to read the lines beggining with *2* so I done:
s = new Scanner(new BufferedReader(new FileReader("example.dat")));
while (s.hasNext()) {
String str1 = s.nextLine ();
if(str1.startsWith("*2*")){
System.out.print(str1);
}
}
So this will read the whole line I'm fine with that, Now my issue is I need to extract the 2nd line beggining with numbers the 4th with numbers the 5th with success and the 7th(DPSRN). I was thinking about using a String dilemeter with | how to extract them once i've used the dilemeter.
View Replies
View Related
Apr 9, 2015
Suppose i have a string S="a.png,b.png,c.xlsx";
I need to extract only c.xlsx, how i will do these in java
View Replies
View Related
Apr 8, 2015
I want to extract a specific String from HTML, specifically, I want to extract a String from in between <...>
So far, I've got this
package main;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
public class HTMLGrabber {
static String allOneString = "";
[code]....
The problem I have is when I change the last parameter in this line:
System.out.println("And the Keywords are:
" +allOneString.substring(allOneString.lastIndexOf("meta name="keywords" content=") + 30, allOneString.indexOf("Fictional History">")+17));
to
System.out.println("And the Keywords are:
" +allOneString.substring(allOneString.lastIndexOf("meta name="keywords" content=") + 30, allOneString.indexOf("">")));
i.e. the generic alternative, I get this error message:
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: -366
at java.lang.String.substring(Unknown Source)
at main.HTMLGrabber.main(HTMLGrabber.java:45)
Is there a better and simple way to extract a substring?
View Replies
View Related
Feb 5, 2014
I've been working quite a bit with a login system the past couple of months and I now have a version that I would like to try "for real" by extracting it as a runnable .jar or .exe file. I've looked at a couple of guides that told me how to do this properly, but even after following every step precisely it didn't work.
One of the guides I tried: 3 Ways to Create an Executable File from Eclipse - wikiHow
Double clicking the file or selecting it and pressing enter does nothing, the computer loads for a second and then nothing happens. I don't receive any visible errors when extracting the program, either.
However, when running the file from the command prompt I do receive an odd error:
Microsoft Windows [Version 6.2.9200]
(c) 2012 Microsoft Corporation. All rights reserved.
C:UsersUserName>java -jar Login.jar
Exception in thread "main" java.lang.IllegalArgumentException: input == null!
at javax.imageio.ImageIO.read(Unknown Source)
at LoginSystem.Data.updateData(Data.java:347)
at LoginSystem.Data.<init>(Data.java:309)
at LoginSystem.MainFrame.<init>(MainFrame.java:42)
at LoginSystem.MainFrame.main(MainFrame.java:457)
C:UsersUserName>
I must say I don't quite understand the error, it seems to be unable to load an image which is odd considering the program works fine without any errors at all in Eclipse.
View Replies
View Related
Mar 25, 2015
code for extracting kerala state vehicle number plate from an image
View Replies
View Related
Dec 8, 2014
I am working on a project that requires me to build a database with random access file, representing products, the base product contains a name (about 30 characters), a price (double), and a quantity (integer). I have worked on this project for probably 15+ hours and have tried so many things and feel like I've barley made any progress...
The part i am really struggling with is taking the data from the text file and creating an object array with it using the product class. Once ive accomplished that, i have to use that data to create a random access file with the data.
Here is the base Product class that must be used to create the objects for the array.
public class Product
{
public String pName;
public String stringName;
public double price;
public int quanity;
[Code] .....
And then here is the data from the text file that i must extract to use to create product objects.
Dill Seed,938,34
Mustard Seed,100,64
Coriander Powder,924,18
Turmeric,836,80
Cinnamon (Ground Korintje),951,10
Cinnamon (Ground) Xtra Hi Oil (2x),614,31
Cinnamon (Ground) High Oil (1X),682,19
These continue for about 40-50 entries, they are not separated by a blank line though i had to add those so it would display correctly, each entry is on its own line with name separated with spaces, then price after a comma, then quantity after the second comma.....
View Replies
View Related
Dec 9, 2014
I am working on a project that requires me to build a database with random access file, representing products, the base product contains a name (about 30 characters), a price (double), and a quantity (integer). I have worked on this project for probably 15+ hours and have tried so many things and feel like I've barley made any progress...
The part i am really struggling with is taking the data from the text file and creating an object array with it using the product class. Once ive accomplished that, i have to use that data to create a random access file with the data. Here is the base Product class that must be used to create the objects for the array.
public class Product
{
public String pName;
public String stringName;
public double price;
public int quanity;
[Code]...
these continue for about 40-50 entries, they are not seperated by a blank line though i had to add those so it would display correctly, each entry is on its own line with name seperated with spaces, then price after a comma, then quanity after the second comma.....
View Replies
View Related
Dec 8, 2014
I am working on a project that requires me to build a database with random access file, representing products, the base product contains a name (about 30 characters), a price (double), and a quantity (integer). I have worked on this project for probably 15+ hours and have tried so many things and feel like I've barley made any progress...
The part i am really struggling with is taking the data from the text file and creating an object array with it using the product class. Once ive accomplished that, i have to use that data to create a random access file with the data.
Here is the base Product class that must be used to create the objects for the array.
public class Product
{
public String pName;
public String stringName;
public double price;
public int quanity;
//Constructor
public Product( String pName, double price, int quanity )
[code]....
and then here is the data from the text file that i must extract to use to create product objects.
Dill Seed,938,34
Mustard Seed,100,64
Coriander Powder,924,18
Turmeric,836,80
Cinnamon (Ground Korintje),951,10
Cinnamon (Ground) Xtra Hi Oil (2x),614,31
Cinnamon (Ground) High Oil (1X),682,19
these continue for about 40-50 entries, they are not separated by a blank line though i had to add those so it would display correctly, each entry is on its own line with name separated with spaces, then price after a comma, then quanity after the second comma.....
View Replies
View Related
Jul 14, 2014
New to programming. Am supposed to create a program that reads a text file (of integers) and computes a series of computations on these integers. I don't have the code for the integers in my code yet, (i know how to do those), but am struggling getting the array to simply print in the print writer. I have the user select a text file, read the file with a scanner, and then save the computations done from my code into another file. specifically, the problem is as follows: Write a program that uses a file chooser dialog to select a file containing some integers. The file contains an integer N followed by N integers. The program then uses a file chooser dialog to let the user specify the name and location of an output file to write results to.The data written to the output file will be as follows
(1) The original list of N numbers from the input file,
(2) The original list of N numbers printed in reverse order of how they appear
in the input file.
(3) The sum and average of these numbers,
(4) The minimum of all the numbers,
(5) The maximum of all the numbers.
[import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Writer;
[Code]....
View Replies
View Related