How To Read Numbers And Names From A Text File
Mar 20, 2014
I have a text file containing numbers and names as shown in the example below:
61133128805241Albert Rosenberg
64763645543509Joel
79256337754219Michael Burton
I'm making a program that will read the file and put the numbers in a list of int arrays and names in another list of strings. In my program i created two classes. One will receive the numbers and the other will receive the names. But i only can read the numbers! How can I read everything and separate into two different lists?
try( BufferedReader br = new BufferedReader( new FileReader( jFileChooser1.getSelectedFile().getAbsolutePath() ) ) ) {
hist = new Historic();//Will recieve the array of numbers.
while( br.ready() ) {
int line[] = new int[ 7 ];
[Code] ...
View Replies
ADVERTISEMENT
Nov 5, 2014
I'm trying to write a program to read the names off of email addresses in a text file and my code is not printing anything to the console. So I want to print everything before the "@" sign. It seems like I'm missing a big thing
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;
public class Email {
public static void main(String[] args) throws FileNotFoundException, IOException {
[Code] ....
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
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
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
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
Jun 30, 2014
I'm supposed to write a program, which reads float numbers from a file, puts them in an array and sorts the array. After that I'm suppose to add the numbers so that when I add the 1 and 2 number of the array, I'm suppose to save the sum on the position of number 1, then I add number 3 and 4 and save the sum on position 2 etc. Also if my array has an uneven number of floats it's suppose to add the last 3 and not 2 numbers in the last iteration. The problem is the method throws an ArrayOutOfBounds Exception but I can't seem to find my mistake.
That's the second method. The first one just stores the sum in another variable and then returns it. Also is there a way in that I can Scanner/File/array etc. and initialize the array only once so I don't write the same code two times like it is now.
package sumOfFloats;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.Scanner;
public class SumOfFloats {
public static float sumFloats() throws FileNotFoundException{
[Code[ ....
View Replies
View Related
Mar 3, 2014
personid gender height class
1 female 1.6 short
2 male 2.0 tall
3 male 1.85 medium
4 female 1.9 medium
5 male 1.7 short
6 female 1.8 medium
7 female 1.95 medium
for eg i have to find minimum and maximum height from column height.
View Replies
View Related
Aug 23, 2014
How to read a text file in Java?
View Replies
View Related
Nov 17, 2014
I have to write a program for sorting an array of random numbers by the users choice. These random numbers are stored in a text file, which the user inputs, and is then stored into an array for sorting. I won't have a problem with the sorting algorithms, but I've never had to read a text file and store it into an array before
The text file has the numbers stored like so :
148
626
817
4
312
652
643
etc....
I gather that I'll probably have to user the Scanner for the user to input the text file name, but how do I store it to an array? So far I only have the bones of the program done, like so
import java.util.Scanner;
public class SortingAlgorithms {
public static void main(String[] args) {
[Code].....
View Replies
View Related
Nov 17, 2014
So I am saving a file. it is an array of two strings each containing three words. i figured out how to save to a text file and read it back in and put it back into an array. I am using scanner.hasnext and scanner.next and i think that separates the strings into variables using the spaces in the strings. Well for my project i need to do it with a symbol instead of a space
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.Writer;
import java.util.Scanner;
[Code] .....
I put some comments in the read method so you can get exactly what im trying to accomplish....
View Replies
View Related
Oct 25, 2014
I am trying to read in lines of text from a file then prints out the text. I only need one 2D array and can't copy from one array to another.This how the file looks like:
4 4
FILE
WITH
SOME
INFO
I have been able to read the file but when I am trying to run my program I have blank spacing instead of an array.
import java.util.Scanner;
import java.io.*;
public class Array {
public static void main(String[] args) throws IOException{
[code]....
View Replies
View Related
Oct 22, 2014
Write a class TextAnalysis14 which reads a text file and allows some text mining(Analyzing). Concretely the program has to support
1. total the number of words,
2. checking whether a word is contained in the text,
3. finding the most frequent word, or words in case there are more than one.
A word is a non-empty string consisting of only of letters (a,. . . ,z,A,. . . ,Z), surrounded by blanks, punctuation, hyphenation, line start, or line end. The analysis is case-sensitive.
View Replies
View Related
Mar 9, 2014
Assignment: Develop a GUI-based program to read the entries of a matrix from a text file. The first number is the number of rows; the second number is the number of columns. The remaining numbers are integers between 1 and 9 in row by row order. Scan the matrix, highlight (display the entries in different color) all cells that form a group of five cells with the same value horizontally, vertically or diagonally.
Example of text(.txt) file:
7 7
3623161
3666669
3936293
3594955
3289867
2493998
1399998
Example of output:
3623161
3666669
3936293
3594955
3289867
2493998
1399998
* ^^this would be what it would look like when displayed in the GUI. But it would be colored. Anything that has 5 in a row ...My Class File:
// GUI-related imports
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Scanner;
// File-related imports
[code]....
EX.
0=black(when there is no combo. of 5)1=blue(horizantal combo of 5)2=red(vertical combo of 5)3=green(right diagnol combo of 5)4=purple(left diagol combo of 5)
View Replies
View Related
Feb 6, 2015
I wanna learn to create a method where I use a scanner or any other way to input.The stuffs I input will be strings. The whole thing will be like a destination creator.So if I input the string USA, it will write this to a file:
1:USA
When I go to the method again the ID will be added so if I input UK, the file will contain:
1:USA
2:UK
Now if I terminate the program, next time when I run it again it will be able to read the ArrayList, so if I wanna go to the method again and write: Norway the file will contain:
1:USA
2:UK
3:Norway
Later I also want to be able to use println to show all of these lines from the file, as well I would like to be able to delete an ID, so if I delete ID 2 the file would contain:
1:USA
3:Norway
I'm quite new to Java, I'm in a Java course since soon 3 weeks back and I have sure learned a lot, all the loops and basic statements that exist in most languages, but now when it comes to this I just don't understand.
View Replies
View Related
Mar 18, 2014
I have problem with writing objects to file. The thing i want to do is write object(Measur) and then read it from Notepad++. Not from program, but normally from computer. When i'm opening my file i see patterns(i dont how to call this). I think, that I need write it as a string in some way. There is my code:
Java Code:
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.Serializable;
class Task3 {
[code]....
View Replies
View Related
Apr 14, 2015
I am learning about arrays in my class and my professor has a habit of throwing in code without explaining. We are doing a program called storing largest numbers where we read data from a file and place the larger of the two numbers in the corresponding position of a third array. They are in 4 by 4 format. Here is the ending code
import java.io.*;
import java.util.*;
public class prog464aStoringLargestNums
{
public static void main(String[] args)
[code]....
View Replies
View Related
Mar 26, 2014
So I'm trying to read 11 values from a text file, each value on a separate line. The first value I use as loop control to run through calculations on the other ten and finally output both the numbers and the calculations to the console and an output file. I'm not getting a compiler error or a runtime error but my loop seems to stop after reading the first line. It also doesnt seem to be writing to my output file but does create it when I run the program. This is what my text file looks like
10
150.4
88.4
-3.14
499.4
799.4
1299.8
0
1900.2
901.7
4444.4
This is what my program looks like
import java.util.*;
import java.io.*;
public class assignment7scratch
{
Toolkit_General toolKit = new Toolkit_General();
public static void main (String[]args)throws IOException
[Code] .....
so I dont get an error but this is what my output looks like
----jGRASP exec: java assignment7scratch
This program reads a list of values representing number of miles driven by individuals. It will output the dollar amount their rental cars cost.
Number of miles traveled on the left as well as amount reimbursed on the right
-----------------------------------------------
Miles Driven Amount reimbursed
150.427.072
----jGRASP: operation complete.
it also doesn't write anything to my output file, though it does create one.
View Replies
View Related
Oct 28, 2014
I have a TxT file with the next content:
[Cars]
BMW=3
Lamborghini=10
[Computers]
Mouse=5
Keyboard=12
How can i read the file and output in
System.out.println("Category " + descriptor + " Value: " + )
The output console should look like :
Cars : Lamborghini 10
BMW 3
Computers: Mouse 5
Keyboard 12
And the Value MUST be readed from thext file for each descriptor.
package test;
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 {
private final String descriptor;
[Code] ....
View Replies
View Related
Oct 28, 2014
I am trying to read numeric values from a text file into an array. This is what i have so far but when i compile it, it doesn't run and give me a result.
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
public class question2_17110538 {
[Code] ....
View Replies
View Related
May 30, 2014
I have a problem about read text file in array and show it to textfield :
Content the file:
I want read line 1 to textfield 1, line 2 to textfield 2,....
View Replies
View Related
Jan 28, 2015
I want to read a text file from the starting point to end of the file.
BufferedReader read=new BufferedReader(new FileReader("C:/eGurkha/agent/sample/UptimeRecord.txt"));
String line=read.readLine();
while (line != null)
{
System.out.println("lines are :"+line)
line=read.readLine();
}
By using the above code I can read all the line from the file, But I want to read from the some starting point.
For example : I have a file with 100 lines, from that file I want to read lines from 53 upto end of the file.
View Replies
View Related
Nov 15, 2014
I'm trying to figure out the necessary code for reading integers from a text file, then placing them withing the two-dimensional array I have created, and then finally printing the array using a nested for-loop. I have attached the file I would like to read from. I'm having trouble figuring out how to reference the text file with the integers, and also how to properly create a dynamic preface for each row of the array. I want the preface to display as "Week #: ", with # being the row number. I tried to create an integer to be used that way, but NetBeans tells me whatever integer I declare has already been defined in method main. I know I need to use scanner to read the file. I would like the output to display like this:
Quote
Temperature Data
Week 1: 73 71 68 69 75 77 78
Week 2: 76 73 72 72 75 79 76
Week 3: 79 82 84 84 81 78 78
Week 4: 75 72 68 69 65 63 65
View Replies
View Related
Dec 9, 2011
I am somewhat of a java newbie (learned it awhile back and just getting back to programming some again.) I have a text file of data much larger than this, but here are the first ten rows and first 10 columns.
39755320111041730140.633038085-2.117082366149.069997
39850320111041730150.633038085-2.117082511148.309997
39955320111041730160.633037998-2.117082293149.509997
40055320111041730170.633037945-2.117082351149.239997
.......
I can read and write all the data back out to files. But I am not sure about a few things.
First would it be best to use BufferedReader and OutputStream such as:
public static void main(String[] args) throws IOException {
BufferedReader bReader = new BufferedReader(new FileReader ("testdata.txt"));
BufferedOutputStream bytesOut = new BufferedOutputStream(new FileOutputStream ("outfile.txt"));
Second, I was then going to initialize an array but I might have 30 or more columns of data, of which I might perform and output only 10 columns to my output.txt file so is this a good way?
Third, I only want to perform operations (such as average the data, convert units or multiply two columns together) on 10 of the 30 plus columns and print out results to output.txt file. For example, In testdata.txt file above, I want to skip first seven columns. I then want to take column 8 and multiply by 100 then divide by 3 and output result to output file. I want to do same for column 9. Column 10 I want to multiply by different number (by 3.5).
View Replies
View Related
Oct 16, 2014
how to sort my text file. So far I have been able to read the text file and print it back out, but I am unsure of how to go about sorting it. Must print the colors (in the order of the rainbow first) and if the colors are the same compare the size (bigger is more important)The values I have to sort are written as such in the text file:
blue 18
blue 10
red 27
yellow 4
public class Rainbow{
private String color;
private int size;
public Rainbow(String color, int size){
this.color = color;
this.size = size;
[code]....
I would know how to sort it if it was supposed to be alphabetical order or there were only numbers, but I can't seem to figure out how to sort it when there are strings and integers
View Replies
View Related
Apr 7, 2014
I have a source code here that counts the frequency of alphabetic characters and non-alphabetic characters (see the source code below).
import java.io.*;
public class letterfrequency {
public static void main (String [] args) throws IOException {
File file1 = new File ("letternumberfrequency.txt");
BufferedReader in = new BufferedReader (new FileReader (file1));
[Code] ....
But, let's just say that now I have the following characters in the text file, "letternumberfrequency.txt":
71 geese - 83 cars - 58 cows- 64 mooses- 100 ants- 69 bangles- 90 molehills - 87 noses
The numbers inside that text file would be considered as strings, am I right? But I want to extract the numbers so that I can also be able to count their frequency - not as individual digits but as whole numbers (that is how many "71", "83", "58", "64", etc. are there...). Would using "Double.parseDouble ()" work?
View Replies
View Related