Read Input File And Create Output With Anagram For Words In File

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


ADVERTISEMENT

Read A File And Then Output Back To Same File On New Line

Jan 24, 2015

I am trying to write to a file but everything I have tried doesn't seem to work. What I want to do is read a file and then output back to the same file on a new line. The text file contains the sentence "Java is a programming language".

import java.util.Scanner;
import java.io.*;
class HW1B {
public static void main(String[] args) {
Scanner fileIn = null;
try {
fileIn = new Scanner (new FileInputStream("text.txt"));

[Code] ....

These are the errors :

HW1B.java:19: error: no suitable constructor found for Scanner(FileOutputStream)
fileOut = new Scanner (new FileOutputStream("text.txt"));
^
constructor Scanner.Scanner(Readable) is not applicable
(argument mismatch; FileOutputStream cannot be converted to Readable)
constructor Scanner.Scanner(InputStream) is not applicable

[Code] ....

Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
2 errors

View Replies View Related

Read Txt File And Add Words To ArrayList As Strings - Index Out Of Bounds

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

Read File And Input Each Line Of File Into Array

Mar 21, 2015

I am trying to read a file and input each line of the file into an array. I have not set the array size as I was hoping to fill the array using a while loop. Unfortunately the scope of the array does to work inside the while loop so I am being told that the array 'students' has not been initialised even though it has just outside of the while loop. Is it possible to do what I am trying to without having the array initialised in the while loop as surely the array will be reset every time if it was in the while loop? Here is my code:

public static void students(String file) throws FileNotFoundException {
try {
File studentInfo = new File(file);
Scanner input = new Scanner(studentInfo);
String[] students;

[Code] ....

View Replies View Related

Implementing Read File And Output In Console

Oct 28, 2014

I have the file test.txt that include:

[Computers]
Keyboard=10
Mouse=5
[Cars]
Lamborghini=6
BMW=3

The [Computers] , [Cars] are Category, Keyboards, Mouse,Lamborghini, BMW, are Descriptors and the numbers are values

I have this code until now.

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;
import java.util.Map;
public class Descriptor {

[Code] .....

All I want is that my program can read the entire txt file and output in console the Category Descriptors and Value.

Example:

Cars: Lamborghini 6, bmw 3
Computers: Keyboards 10, Mouses 6..

View Replies View Related

Input Ten Words And Output Them Backwards In MSDOS Environment

Sep 4, 2014

how would a program code look like, input ten words and output them backwards in a msdos environment. My code this far is:

package baktext;
import java.util.*;
import java.io.*;
import java.awt.*;
//public static String baklänges(String s) {
//}
public class Baktext {

[Code] ....

View Replies View Related

Read From File Input

Oct 25, 2014

The program is reading from file input. how can I replace hate with love the file contains only one line.I hate programing!

Java Code:

[import java.util.Scanner;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
public class Program3 {
public static void main(String[] args) {
Scanner fileIn = null;

[code]...

View Replies View Related

Create Program That Prompts Input And Creates File With That Input As Name

Jul 14, 2014

So I was going to try to create a program that prompts input and creates a file (That didn't exist before) with that input as name.Then, the program prompts inputs after stating questions such as 1 + 1, then if the user inputs an answer, put "Question # = Correct "or" Wrong.Code SO Far:

Java Code:

import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
public class File_Read {
public File_Read() {//File_Read is the Interactive object

[code]....

So that it puts the Correct or Wrong into the file.

View Replies View Related

Sort User Input 3 Words Alphabetically And Output Middle Word

Feb 8, 2014

I have a project requiring me to build a program having a user input 3 words, sort them alphabetically and output the middle word. I have done some searching and seem to only come back with results for sorting 2 words. I so far have code to get the user input but I am completely lost as to how to sort them alphabetically.

import java.util.Scanner; //The Scanner is in the java.util package.
public class MiddleString {
public static void main(String [] args){
Scanner input = new Scanner(System.in); //Create a Scanner object.
String str1, str2, str3;
System.out.println("Please enter three word words : "); //Prompt user to enter the three words

[Code]...

we havnt done arrays yet and I THINK i have to do compareTo.....how to use it?

View Replies View Related

Use Data Read From File To Create Instances?

Sep 10, 2014

"Write a program (save the program as ProductInventory.java) that will read data about 5 products from a text file (Products.txt. The program should use the data read from the file to create instances (objects) of Product.java(Use Product class as a Reference Type)."

I'm yet to discover how I will get the info from the textfile using scanners but I don't know how to "create instances of a reference type".

This is the code of Product.java that came with the exercise.

public class Product {
private String productCode = "";
private String productName = "";
private int quantity;
private String supplierName = "";
private String supplierAddress = "";
private double price;

[Code] .....

By the way, the exercise also required me to use the abstract class ProductLister. To be clearer, the text file is kinda like this:

54643
Rizer Mouse
Mark5s Merchandising
Marquee Mall
4
205.50
23412
Acer Ultrabook
JohnJade Merchandise
Cornal City
2
62200.00
93112
Dell Ultrabook
Octagon Marketing
Cornal City
3
68900.00
22126
Macbook Air Pro
Computerware Services
San Beda, Chad
2
93500.00

View Replies View Related

Why Won't Read Input File (WordPad Document)

Sep 12, 2014

I keep receiving an error in which State.Fall.txt can not be read. I can't point it directly to a drive because someone else needs to open it. I saved it in wordpad as a text file. My question is what did I do wrong in my code that it can't directly access the wordpad document? 
 
import java.io.*;
public class Main {
/**
* @param args the command line arguments
*
*/
public static void main(String[] args) throws IOException
{
// Create an array of individual state objects to hold 50 items

[Code] ....

View Replies View Related

How To Use File Input / Output In Addition To Exception Handling

Dec 2, 2014

I am trying to learn how to use file input/output in addition to exception handling... The problem is my textbook wrote this chapter for a version of Java that hasn't come out yet, so everything I do "according to the textbook" doesn't work. any feedback on correcting these exception errors because I am not sure what is causing them or how to fix them.

I was able to have it display the name of the book in the Book.txt file, but when I added the second part if the file doesn't exist, that's when the errors came up and it wouldn't compile.

import java.io.*;
import java.util.*;
public class DisplayBook
{
public static void main(String[] args) {
try {
File book = new File("Book.txt");
FileInputStream in = new FileInputStream(book);

[Code]...

These are the compilation error messages I am receiving: (I have managed to get it down from 7 errors to just 4, but now I'm stuck)

DisplayBook.java:15: error: unreported exception IOException; must be caught or declared to be thrown
while ((letter = in.read()) != -1) //if file exists, displays book title
^
DisplayBook.java:24: error: unreported exception FileNotFoundException; must be caught or declared to be thrown

[Code] ....

4 errors

View Replies View Related

Create Individual XML Files From Parsed Data Output Of XML File?

Feb 26, 2015

I have written a program (DOM Parser) that parses data from a XMl File. I would like to create an individual file with the corresponding name for each set of data parsed from the xml document. If the parsed output is Single, Double, Triple, I would like to create an individual xml file (Single.xml, Double.xml, Triple.xml)with those corresponding names. How do I create the xml files and give each file the name of my parsed data output?

import java.io.IOException; 
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;

[code]....

View Replies View Related

How To Create Individual XML Files From Parsed Data Output Of XML File

Feb 26, 2015

I have written a program (DOM Parser) that parses data from a XMl File. I would like to create an individual file with the corresponding name for each set of data parsed from the xml document. If the parsed output is Single, Double, Triple, I would like to create an individual xml file (Single.xml, Double.xml, Triple.xml)with those corresponding names. How do I create the xml files and give each file the name of my parsed data output? 
 
import java.io.IOException;import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;import org.w3c.dom.Element;

[Code] ....

View Replies View Related

Make Library That Will Read Some Input Files From A File?

Apr 23, 2015

I am trying to make a Library that will read some Input Files from a File . Like When We Enter Nuber from a System.in

1
2
45
667

77
34

and then store these values in int[] array

What I want is I Save all these values in a File and at Run time pass path of that file to command line arguments and then int[] array will be initialize using that

something like this [URL]

View Replies View Related

Read Line Of Input For A File - String Tokenizer

Jan 27, 2015

So I'm having a problem with the .hasMoreElement() method. I try to read lineOfInput for a file which contains:

Hobbit, Long,t@gmail.com,475-555-4444,3
Long, Hobbit,b@yahoo.com,445-222-5342,2
Hobbit,Long,b@yahoo.com,465-222-5342,2
Help,Yerp,,455-222-2222,4

but when i get to the ,, on the last line I get a NoSuchElementException and the program crashes.

StringTokenizer inputField = new StringTokenizer(lineOfInput, ",");
while(inputField.hasMoreElements()) //for each fields is a line
{
lastName = inputField.nextElement().toString();
firstName = inputField.nextElement().toString();
email = inputField.nextElement().toString();
phoneNumber = inputField.nextElement().toString();
level = Integer.parseInt(inputField.nextElement().toString());
}

View Replies View Related

Unable To Read Input File When Adding Pictures To A JFrame

Aug 25, 2014

i've tried changing the path 10000 times. idk if its wrong in the code.

Java Code: import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

[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

Create A Java Program That Can Read Specific Data Within Csv File To Work Out Averages

Aug 7, 2014

i am fairly new to java but have made a few projects so i do know most aspects that would allow me to complete the task its just i have been stuck at the same place now for 2 days.The project is to create a java program that can read specific data within a csv file to work out the averages etc. The csv file is a database of different weather stats . an example of the first 12 months of the csv file is below..

[CSV FILE]

year ,month,average rainfall etc

1946 15.70.616108.131.5
1946 28.23.56111.871
1946 38.82932.9 102.9
1946 414.16.3029.2 150.5
1946 513.96060.7 143.6

[code]...

I know that once the data is indexed i can than use a double to find the average of the 12 specific pieces of data and so on. once this is complete i should than be able to transfer the data to a simple graph.

View Replies View Related

Reading Text File With Specific Input Format - Output Formatted Report

Apr 10, 2014

Here's a link to it : [URL] ....

The basic gist is it's "A program that reads in a text file that uses a specific input format and uses it to produce a formatted report for output."

Specifically :"For this lab you will write a Java program that produces a simple formatted report. The program will prompt the user to enter a file name. This file must contain information in a specific format (detailed below). Each "block" of the file contains information for one player in a competition -- the name of the player followed by a number of different scores that that player achieved. The program should find each player's average score, median score and best and worst scores and display them in a line on the final summary report. The program should also determine which player has the highest average score and which player has the lowest average score."

I get the following errors when I try and compile it:

Enter an input file name: Project11.txt
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException... -1
at java.util.ArrayList.elementData(Unknown Source)
at java.util.ArrayList.get(Unknown Source)
at Project11.getMedian(Project11.java:68)
at Project11.main(Project11.java:27)

I get that the error(s) reside in lines 68 and 27, among problem other areas, but I'm not exactly sure how I can fix them.

Here's my code:

import java.io.*;
import java.util.*;
public class Project11 {
public static void main(String[] args) throws IOException{
Scanner in = new Scanner(System.in);
System.out.print("Enter an input file name: ");
String input = in.nextLine();

[Code] ....

View Replies View Related

How To Take Input Text File With Terms And Create Glossary With Hyperlinks

Nov 28, 2014

I'm working on a project where I have to take an input text file with terms and create a glossary with hyperlinks. I've got it working halfway. It outputs the html files for some but not all of the terms and I can't figure out why.

I'm getting these errors:

Please enter the location of the input file: data/terms.txt
Please enter the location for the glossary: data/testOutput
Exception in thread "main" java.util.ConcurrentModificationException
at java.util.LinkedList$ListItr.checkForComodification(LinkedList.java:953)

[Code] .....

How would I fix them??

Code :

import java.util.Comparator;
import components.map.Map;
import components.map.Map2;
import components.queue.Queue;
import components.queue.Queue2;
import components.sequence.Sequence;

[Code] ....

View Replies View Related

Program To Read Input Of Morse Code And Then Produce Output Of English

Aug 25, 2014

I'm having some trouble with getting this program to read an input of morse code and then produce an output of English. When typing in morse code for the phrase 'the string', the output looks something like this:

- .... .
t
h
... - .-. .. -. --.
s
t
r
i
n

The English-->Morse works just fine.

import java.util.Scanner;
public class project1
{
static final String[] alpha = {
"a", "b", "c", "d", "e", "f", "g", "h", "i",
"j", "k", "l", "m", "n", "o", "p", "q", "r",
"s", "t", "u", "v", "w", "x", "y", "z", " "

[Code] .....

View Replies View Related

Read Text File Into Object Array And Creating Random Access File

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

Read Text File Into Array Ask User To Save File And Print Data

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

JSP :: How To Browse And Read A File In Page To Perform Encryption For File

Nov 12, 2014

I am trying to create a file browse option in my jsp and later after browsing, all i want to do is to read that file in my jsp without saving it into that database so that i can perform encryption for it and save that encrypted file later into my database. please provide reference link so that i can refer to some applications and and move ahead with my work.

View Replies View Related

JSP :: Read Log File And Trigger Email With Same File Attached

Apr 6, 2015

I want to read the contents of a log file present on the server, and trigger email along with the log file attached using JSP.

View Replies View Related







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