Reading in a txt file, appending numbers to it.

So I'm a student at Georgia Tech working on a relatively simple Java program for a research internship, but it's been awhile since I've had my Java course and I'd really like some help on this. Basically, what I'm looking to do is to take in a text file with data that only consists of the numbers 1,2,4 and 5, with up to four digits in each line and no number may be repeat itself in the same line. A sample of data would look like the following:
12
21
154
2
1
45
24
4125
Lines like '12' and '21' would count as the same however, as would '4512' to '1245'. I'm trying to determine how often each number 'interacts' with each other number, and then append that data to the end of the text file by saying something along the lines of:
One-Two Interactions = 4
Four-Five Interactions = 6
Etc. etc. The real problem I'm having is I can't remember how to get the BufferedReader to 'identify' the particular numbers and combinations of numbers before adding to the count in each variable. If you have any advice or answers, it would be greatly appreciated.

import java.io.*;
import java.util.*;
public class ExchangeProgram{
     public static void main(String[] args) {
          int one = 0;
          int two = 0;
          int four = 0;
          int five = 0;
          int one_two = 0;
          int four_five = 0;
          int one_four = 0;
          int two_five = 0;
          int four_two = 0;
          int one_five = 0;
          int one_two_four = 0;
          int two_four_five = 0;
          int one_two_five = 0;
          int one_four_five = 0;
          int all = 0;
          Set h = new HashSet();
          File file = new File("test.txt");
StringBuffer contents = new StringBuffer();
BufferedReader reader = null;
try
reader = new BufferedReader(new FileReader(file));
String text = null;
// repeat until all lines is read
while ((text = reader.readLine()) != null)
                         h.add(text);
} catch (FileNotFoundException e)
e.printStackTrace();
} catch (IOException e)
e.printStackTrace();
} finally
try
if (reader != null)
reader.close();
} catch (IOException e)
e.printStackTrace();
          for (int i=0; i>h.size(); i++){
                    if (h.contains("1")){
                         one++;
                    if (h.contains("2")){
                         two++;
                    if (h.contains("4")){
                         four++;
                    if (h.contains("5")){
                         five++;
                    if (h.contains("12")){
                         one_two++;
                    if (h.contains("45")){
                         four_five++;
                    if (h.contains("14")){
                         one_four++;
                    if (h.contains("25")){
                         two_five++;
                    if (h.contains("42")){
                         four_two++;
                    if (h.contains("15")){
                         one_five++;
                    if (h.contains("124")){
                         one_two_four++;
                    if (h.contains("245")){
                         two_four_five++;
                    if (h.contains("125")){
                         one_two_five++;
                    if (h.contains("145")){
                         one_four_five++;
                    if (h.contains("1245")){
                         all++;
// show file contents here
System.out.println(one_two);
Here's what I've come up with so far, though I'm getting this error: Note: Recompile with -Xlint:unchecked for details.
Any comments on any major mistakes I'm making here? Haven't used the Set interface much before.

Similar Messages

  • Apostroph and euro sign not read corectly from txt file

    apostroph and euro sign not read corectly from txt file.
    my code is like this:
    FileInputStream fis= new FileInputStream(x+".html");
    BufferedReader br=new BufferedReader(new InputStreamReader(fis,"UTF-8"));
    String Line="";
    while ((Line = br.readLine()) != null) result+=Line;
    br.close();
    fis.close();
    I use UTF-8 because the file contains also French characters.
    What's the problem?
    THANK YOU!

    apostroph and euro sign not read corectly from txt
    file.
    my code is like this:
    FileInputStream fis= new FileInputStream(x+".html");
    BufferedReader br=new BufferedReader(new
    InputStreamReader(fis,"UTF-8"));
    String Line="";
    while ((Line = br.readLine()) != null) result+=Line;
    br.close();
    fis.close();
    I use UTF-8 because the file contains also French
    characters.
    What's the problem?
    THANK YOU!
    This is from the FileInputStream API documentation:
    FileInputStream is meant for reading streams of raw bytes such as image data. For reading streams of characters, consider using FileReader.

  • Read .txt file of numbers and draw

    Hello.
    I am trying to utlize BufferedReader and g.drawline to read numbers from a text file and output to the screen as a "line".
    I know I still need a while loop and some error checking, but, am having trouble finishing the more 'basic' portion of the code.
    The GUI class is already taken care of. I am just trying to open the file, read, turn to int, produce lines, then close file.
    I have commented out some of the code that was provided with the assignment.
    Any help would be appreciated.
    Thank you.
    import javax.swing.*;
    import java.awt.*;
    * DrawingPanel creates a panel used for drawing
    * a map
    * Numbers stored in text file, usa.txt.
    * one number per line.  Read each number
    * create a map on screen. GUI provided in a
    * 2nd class.
    public class DrawingPanel extends JPanel {
         /** Graphics object used for drawing on the panel */                           
         private Graphics g;                  
         /** Tells if it is time to draw */
         private boolean timeToDrawPath;
         /** The filename of the hurricane path */
                                  //private String pathFile; 
         private String usa.txt;
         * Creates a new, white DrawingPanel for drawing the maps
         public DrawingPanel() {
              setBackground(Color.white);
              this.timeToDrawPath = false;
                                  //this.pathFile = null;
              this.usa.txt = null;
         * This method is called automatically by Java.  There will NEVER
         * be a direct call to paint() anywhere in the code.  Anytime that we
         * need to update what is drawn on the screen, we call repaint().
         * @param grph The graphics window to paint
         public void paint(Graphics grph) {
              g = grph;
              super.paint(g);
              processUSA();
              if (timeToDrawPath){
                   drawPath();
         * Reads the USA coastline coordinates from a file and draws the path
         * to the panel
         public void processUSA( ) {
                        //just an example of how to draw a single
                        //line segment from (50,50) to (200,200)
                        //g.drawLine( 300, 50, 200, 200);
         //Insert the while loop here??
         //Include the parse.Int statement
         //Open the file
         String inFile = ("usa.txt");
         FileReader fileReader = new FileReader (inFile);
                   //BufferedReader bufReader = newBufferedReader (fileReader);
         BufferedReader bufReader=newBufferedReader (new fileReader ("usa.txt"));
                        //Insert beginning of while loop here????
         //read data from the file
         String str=bufReader.readLine();
         g.drawLine(x1,y1,x2,y2);
         }

    Yep, you are right in deciding the positioning of the while loop.
    But the folly you are committing is while creating object of BufferedReader ... It is to be created by passing to the constructor, the reference of the FileReader object you have created.
    so the line of code shud look like ...
    BufferedReader bufReader = new BufferedReader(FileReaderObject);
    And then you can go ahead with readLine() as per your requirement in the while loop.

  • How to read data from txt file respectively

    Hi,
    I am triying to form an equation between two known points. I want to do this with the attached VI, the most critical point is that I will read the x1, y1, x2 and y2 coordinates from the same .txt file. They will be written in a .txt file and I will send them to the appropriate channel (x1, y1, x2 and y2) respectively. How can I get data in a rule from a .txt file?
    Could anyone please help me with this issue,
    Best regards. 
    Attachments:
    read from txt file.vi ‏8 KB

    Dear RavensFan,
    Thank you very much for your helps, I am bit new to labview so I usually can not find the appropriate functions easily. And a new problem has rised in my application. I should write the A, B and C numbers in the respective series to the file 2.txt. I am able to write them in a straight forward case but I want to write the next triples (A B C) in the next row. Like this;
    A1 B1 C1
    A2 B2 C2
    A3 B3 C3
    So how can I put new line constant and space constant to my VI? 
    Waiting for your valuable helps,
    Best regards,
    Attachments:
    read_from_txt_fileMOD.vi ‏18 KB

  • Reading values from txt file

    Hi,
    I was hoping someone could help me. I am trying to read these values
    3.182, 0.02734, 1126.0, 4.998E-4, 0.01581, 11.0, -150.3, 10.46, 3.735, 0.8474, -0.4854, 0.7866, 1.475, 0.9439, 0.769, 0.1846, 0.07678, -0.9491, -1.236, -0.9908, 0.5265, -0.27, 0.3569, -0.09167, 0.1295, -0.04507, 0.1029, -0.03005, 0.0, 0.03752, 0.001151, 0.2935, 74.84, 19080.0, 6.086, etcfrom a txt file. I have done some coding on it but dont seem to be getting the desired results. I want to take these values and put them in a 2D array.. but its not doing it. Can you see any mistakes i have done please ?
    public double[][] readFile(){
              double[][] dArray = new double[164][37];
              int a  = 0;
            int b = 0; 
                    try
                    {  FileReader fin = new FileReader("myFile.txt");
                               BufferedReader in = new BufferedReader(fin);
                                 String line;
                                 while((line = in.readLine()) != null){
                                String[] value = line.split(", ");
                                for (int x=0; x<value.length ; x++){
                                     System.out.println("a:  "+a+" || b: "+b);
                                         if (b == 37) {
                                                a = a++; 
                                            } else
                                                dArray[a] = Double.parseDouble(value[x]);
                             System.out.println("value: "+dArray[1][1]);
                             b++;

    Yes thats because its part of larger code.. it is just a method within my code.
    but your right about the catch but so yeah sorry i missed it when i copied pasted. I ve also added you a main method.
    public double[][] readFile(){
              double[][] dArray = new double[164][37];
              int a  = 0;
            int b = 0; 
                    try
                    {  FileReader fin = new FileReader("myFile.txt");
                               BufferedReader in = new BufferedReader(fin);
                                 String line;
                                 while((line = in.readLine()) != null){
                                String[] value = line.split(", ");
                                for (int x=0; x<value.length ; x++){
                                     System.out.println("a:  "+a+" || b: "+b);
                                         if (b == 37) {
                                                a = a++; 
                                            } else
                                                dArray[a] = Double.parseDouble(value[x]);
                             System.out.println("value: "+dArray[1][1]);
                             b++;
              catch (IOException e){}
              return dArray;     
    public static void main(String[] args) {
              new Extract();
              }/code]

  • Security restrictions , how to read access a txt file supplied in a jar

    I had written a simple application which uses file handling to display random line from a file on a swing window
    but I do not know how to give my web application permission to access a file
    when I set security permission to all, then error says the application cannot load because the code require unrestricted acess to system resources and is unsigned, I don't know how to get that certificate and I am only doing it for learning purposes.
    when I remove security permissions then it says
    access denied java.io.FilePermissions geekjoskes.txt readPlease help
    I locally signed the jar file, and give my jnlp fiel all permissions, worked fine in my system but when I access same file from local lan it sho errors ,
    please help, I have my txt file stored in my jar file with main class
    the whole jnlp file is
    <?xml version="1.0" encoding="utf-8"?>
    <!-- JNLP File for geek jokes -->     
    <jnlp spec="1.0+"
           codebase="http://localhost/javasoft/webstart/"
          href="geekjokes.jnlp">
       <information>
          <title>Geek Jokes</title>
          <vendor>Vaibhav Mishra</vendor>
          <description>Geeky jokes</description>
          <homepage href="http://scjpbeginner.blogspot.com"/>
          <description kind="short">shows random jokes</description>
          <offline-allowed/>
       </information>
       <resources>    
            <jar href="GeekJokes0.1.jar"/>  
         <j2se version="1.6+"
               href="http://java.sun.com/products/autodl/j2se"/>
         <icon href="geekjokes.gif"/>
       <icon kind="splash" href = "geekjokes.gif"/>
       </resources>
       <security>
          <all-permissions/>
       </security>
       <offline-allowed/>  
       <application-desc main-class="GeekJokes"/>
    </jnlp>Edited by: 76jsr on Aug 7, 2008 3:45 PM
    Edited by: 76jsr on Aug 7, 2008 3:49 PM

    >
    I am extremely thankful to you and finally my first little app is working thanks to you,
    here is it's link
    [http://profile.iiita.ac.in/IIT2006117/javasoft/webstart/geekjokes/geekjokes.jnlp|http://profile.iiita.ac.in/IIT2006117/javasoft/webstart/geekjokes/geekjokes.jnlp] >
    I am glad you got it working! But that launch file is still slightly invalid.
    Here is a corrected, and slightly optimized (you can leave the prefix off the href, if it is the same as the codebase), version of it.
    <?xml version="1.0" encoding="utf-8"?>
    <!-- JNLP File for GeekJokes 0.3 app -->
    <jnlp spec="1.0+"
          codebase="http://profile.iiita.ac.in/IIT2006117/javasoft/webstart/geekjokes"
          href="geekjokes.jnlp">
       <information>
          <title>GeekJokes App</title>
          <vendor>Vaibhav Mishra</vendor>
          <homepage href="http://scjpbeginner.blogspot.com"/>
          <description>Geeky Jokes</description>
          <description kind="short">Cshows random jokes</description>
          <offline-allowed/>
       </information>
       <resources>
           <j2se version="1.6+"
               href="http://java.sun.com/products/autodl/j2se"/>
           <jar href="GeekJokes0.3.jar"/>
       </resources>
       <application-desc main-class="Process"/>
    </jnlp>Very 'Geeky', BTW. ;-)
    Another few things I noted when I looked at it.
    1) There is a stray thread going after the JOptionPane is dismissed. The VM does not end, and the console (if you have it configured to pop-up for JWS apps.) stays on-screen.
    2) If all the jokes are prefixed by '* ' I would recommend removing it from every line of the source file and either re-adding it at runtime, or (preferably) not adding it at all (since it is redundant).
    3) Reconfigure the app. into a loop, and offer the user a JOptionPane with "Another Joke"/"End" instead of "OK".
    4) You can always remove that debugging line I inserted in the code to show the path to the Jar - it was just intended as a 'sanity check' during testing.
    5) Why is it Java 1.6+? JOptionPane was introduced in Java 1.2 with the first Swing implementations, and the I/O is compatible with Java 1.1.
    >
    Thanks again!!!!>Thanks are best expressed (to me) in the notation of a helpful/correct answer (which you have done), and the assignation of (the remaining) dukes*. ;-)
    * After all - checks the title - we have gotten entirely around those 'security restrictions' in a sandboxed application. The reason being that File objects are rarely the correct choice, for applets or JWS apps.

  • Reading from a txt file and storing into a list

    i want to read a list of counters(String) which are there in a flat txt file and store them into a List.
    Any suggestion will be helpful
    sanjeev

    Try this
    try {
              FileReader fr = new FileReader("C:/abc.txt");
              BufferedReader br = new BufferedReader(fr);
              String record = null;
              while ((record = br.readLine()) != null)
                   System.out.println(record );     
              

  • READING AND WRITING TXT FILE, GUI COMPONENTS.

    HI GUYS I AM JUST NEW TO JAVA AND I AM TRYING TO LEARN SOME MORE IN JAVA. SO I NEED HELP FROM YOU GREAT GUYS WHO KNOWS MORE & MORE THING THAN ME. I CODE A GUI FOR THIS PROGRAM. THE CODE IS BELOW.
    This program has to read a txt file to create Food objects which will consist of a food name, a serving size, and a number of calories. A text file is read which contains the calories contained in specific food items. From this data, an array of Food objects will be created and used to populate a combo box for user selection. The Food objects will also be used in calculating the balance calories for a given user on a given day.
    User input will be used to create User objects which will be user name, age, gender, height, weight, and Food Diary objects (composition). The Food Diary objects will consist of Date (composition), Food object (composition), number of servings, and a balance. Food Diary objects will consist of the activity on any given day (see text area in sample output screen below). All User objects are saved to a file as objects and can be retrieved on subsequent runs of the program.
    The program will calculate the number of calories the user is allowed per day to maintain the user�s current weight (see below for formula to use for this).
    BMRMen = 66 + (13.7 * weightPounds/2.2) + (5 * heightInches*2.54) - (6.8 * age)
    BMRWomen = 655 + (9.6 * weightPounds/2.2) + (1.8 * heightInches*2.54) - (4.7 * age)
    GUI CODE
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class FoodDiaryGUI extends JFrame implements ActionListener {
         JLabel               lblName, lblAge, lblWeight,lblHeight,lblFemale,lblMale,lblFood;
         JTextField          txtName, txtAge, txtWeight,txtHeight;
         JButton               btnSave, btnNewUser;
         JTextArea           outputArea;
         JComboBox          cbFood;
         int currentIndex=0, lastIndex=4;
         public FoodDiaryGUI()
              super ("Food Diary Calculator");
              lblName=               new JLabel("Name: ");
              lblAge=                    new JLabel("Age: ");
              lblWeight=               new JLabel("Weight(lbs): ");
              lblHeight=               new JLabel("Height(inches): ");
              lblFemale=               new JLabel("Female: ");
              lblMale=               new JLabel("Male: ");
              lblFood=               new JLabel("Choose a Food: ");
              txtName=               new JTextField(15);
              txtAge=                    new JTextField(3);
              txtWeight=               new JTextField(6);
              txtHeight=               new JTextField(6);
              outputArea=               new JTextArea(9,20);     
              cbFood=                    new JComboBox();
              cbFood.setPreferredSize(new Dimension(100, 20));
              Container c = getContentPane();
              JPanel northPanel = new JPanel();
              northPanel.setLayout(new FlowLayout());
              btnSave=               new JButton("SAVE");
              northPanel.add(btnSave);
              btnNewUser=               new JButton("NEW USER");
              northPanel.add(btnNewUser);
              btnSave.addActionListener(this);
              btnNewUser.addActionListener(this);
              JPanel centerPanel = new JPanel();
              centerPanel.setLayout(new FlowLayout());
              centerPanel.add(lblName);
              centerPanel.add(txtName);
              centerPanel.add(lblAge);
              centerPanel.add(txtAge);
              centerPanel.add(lblWeight);
              centerPanel.add(txtWeight);
              centerPanel.add(lblHeight);
              centerPanel.add(txtHeight);
              centerPanel.setLayout(new FlowLayout());
              JRadioButton rbMale = new JRadioButton(maleString);
         birdButton.setMnemonic(KeyEvent.VK_M);
         birdButton.setActionCommand(maleString);
         birdButton.setSelected(true);
         JRadioButton rbFemale = new JRadioButton(femaleString);
         catButton.setMnemonic(KeyEvent.VK_F);
         catButton.setActionCommand(femaleString);
         //Group the radio buttons.
         ButtonGroup group = new ButtonGroup();
         group.add(rbMale);
         group.add(rbFemale);
         //Register a listener for the radio buttons.
         rbMale.addActionListener(this);
         rbFemale.addActionListener(this);
         public void actionPerformed(ActionEvent rb) {
         picture.setIcon(new ImageIcon("images/"
         + rb.getActionCommand()
         + ".gif"));
              radioGroup.add(rbMale);
              radioGroup.add(rbFemale);
              centerPanel.add(rbMale);
              centerPanel.add(rbFemale);
              centerPanel.add(lblFood);
              centerPanel.add(cbFood);
              JPanel southPanel = new JPanel();
              southPanel.setLayout(new FlowLayout());
              southPanel.add (outputArea);
              c.add(northPanel,BorderLayout.NORTH);
              c.add(centerPanel,BorderLayout.CENTER);
              c.add(southPanel,BorderLayout.SOUTH);
              setSize(650,300);
              setVisible(true);
              //add listener to button components.
              public void actionPreformed(ActionEvent e)
                   if (e.getSource()==btnSave)
                        currentIndex++;
                        currentIndex--;
              public static void main (String[] args)
                   FoodDiaryGUI application = new FoodDiaryGUI();
                   application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              public void actionPerformed(ActionEvent arg0) {
                   // TODO Auto-generated method stub
    THE .txt file is as:
    1000 ISLAND, SALAD DRSNG,LOCAL*1 TBSP*25
    1000 ISLAND, SALAD DRSNG,REGLR*1 TBSP*60
    100% NATURAL CEREAL *1 OZ*135
    40% BRAN FLAKES, KELLOGG'S*1 OZ*90
    40% BRAN FLAKES, POST*1 OZ*90
    ALFALFA SEEDS, SPROUTED, RAW*1 CUP*10
    ALL-BRAN CEREAL*1 OZ*70
    ALMONDS, WHOLE*1 OZ*165
    ANGELFOOD CAKE, FROM MIX*1 PIECE*125
    APPLE JUICE, CANNED*1 CUP*115
    i hope this forum site has to many java professionals and this problem is nothing for them. for me it is great.

    Stick to using a single userid and a single posting of a question:
    http://forum.java.sun.com/thread.jspa?threadID=731264&tstart=0

  • Reading/getting external .txt files

    Hi,
    I want to display the content of a .txt files (which is located in the src folder) inside a TextBox (or ChoiceGroup, or Form). How do I do this yea? For instance, the TextBox constructor is TextBox(String title, String text, int maxSize, int constraints) rite, how do I fit in the file reading function or value that I get from reading the .txt file into it yea?
    Thanx!

    what do u mean by build the .txt file into the jar?{color:#0000ff}http://java.sun.com/docs/books/tutorial/deployment/jar/index.html{color}
    i tried the examples from ... ...In future, please do not post on long-dead threads. One of those threads you posted on was from 2002.
    Reviewing your initial post and the silly question about the TextBox constructor, I think you are not quite ready for this task. You need to go back to basics and learn the Java language. The Sun Java Tutorials are a good place to start.
    This comment is not meant to discourage you, it is a statement of fact. A good foundation is a must for any developer, or indeed in any sphere of activity.
    db

  • I am trying to read in a .txt file, but I have a FileNotFound Exception

    So I am trying to read in as5.txt. It is located in the Assignment5 folder. I probably just have the syntax wrong, but can someone help me?
    import java.util.Scanner;
    import javax.swing.JFrame;
    import java.awt.Color;
    import java.io.*;
    public class Driver {
         public static void main(String [] args){
              JFrame window = new JFrame ("Window");//This creates the window
              window.setBounds(30, 100, 700, 700);
              window.setVisible(true);
              window.setLayout(null);
              FileReader as5 = new FileReader("Assignment5.as5.txt");
              Scanner file = new Scanner(as5);
              GameSquare square = new GameSquare(window, 0, 0);
              GameSquare[][] board = new GameSquare[8][8];
              int x = 0;
              int y = 0;
              for(int i=0;i < 8; i++){
                   for(int j=0;j < 8; j++){
                        board[i][j] = new GameSquare(window, x, y);
                        x=x+80;
                   x=0;
                   y=y+80;
    }

    If you think a file doesn't exists when you think it should, you can use code like this to print out what files are there:
    import java.io.*;
    public class Periscope {
        public static void check(File file) {
            if (file.exists()) {
                System.out.println("file exists: " + getPath(file));
                System.out.println();
                System.out.println("DUMP:");
                System.out.println();
                dump(file, "");
            } else {
                System.out.println("file does not exist: " + getPath(file));
                goUp(file);
        static void goUp(File file) {
            File parent = file.getAbsoluteFile().getParentFile();
            if (parent == null) {
                System.out.println("file does not have a parent: " + getPath(file));
            } else {
                check(parent);
        static void dump(File file, String indent) {
            System.out.println(indent + getPath(file));
            File[] children = file.listFiles();
            if (children != null) {
                indent += "    ";
                for(File child : children) {
                    dump(child, indent);
        static String getPath(File file) {
            try {
                return file.getCanonicalPath();
            } catch (IOException e) {
                e.printStackTrace();
                return file.getName();
        public static void main(String[] args) {
            check(new File("foo.bar"));
    }

  • Help in reading a csv txt file!

    hey i have a problem with this code, Im trying to read a txt file, containing users and scores, and list scores separate, but I get the fist 3 scores empty(0) can any one help plz?
       String uname;
        int theScore;
        int noScores = 0;
        int [] scores;
         public highScores()
            try
                   FileReader gamers = new FileReader( "Gamers.txt" );
                  BufferedReader br = new BufferedReader( gamers );
                  String stringRead = br.readLine( );
                  while( stringRead != null )
                        StringTokenizer st = new
                              StringTokenizer( stringRead, "," );
                      String uname = st.nextToken( );
                      theScore = Integer.parseInt( st.nextToken( ) );
                      noScores = noScores + 1;
                      scores = new int[noScores];
                      for(int i = (noScores - 1);i < noScores;i++)
                              scores[i] = theScore;
                    System.out.println("" + uname + "," + theScore);
                      stringRead = br.readLine( );
                   br.close( );
                   for(int i = 0;i < noScores;i++)
                        System.out.println("" + scores);
              catch( IOException ioe )
              ioe.printStackTrace( );
    //file im reading from (Gamers.txt)
    Usename,1234
    Me,678
    you,456
    them,698
    //output
    Usename,1234
    Me,678
    you,456
    them,698
    0
    0
    0
    698
    Press any key to continue . . .

    Why are you creating the score array inside he while loop? What's that for? It looks like it's for all the scores, but if you have 3 lines, then you're creating 3 different scores arrays--one with 1 element, 1 with 2 elements, and 1 with 3 elements.
    For all but the last one, you're creating it, populating the last element, then throwing it away.
    For the last one, you create it, populate the last element (leaving the first three with their default value of 0) and then that's what gets printed.
    When you have this kind of problem, print out a bunch of relevant stuff (and even some stuff that you think is not relevant) at each step of the way, so ou can see what your code is doing. Yout THINK you know what it's doing, but obviously you're mistaken. If you can't figure it out from staring at it, then you'll have to let the code itself tell you what's really going on.
    You'll have to create the array before you start the while loop, which means you'll have to know ahead of time how many scores you have, or know some maximum that you could possibly have and make it big enough to hold that many.
    Or,instead of an array, you couse use a List, such as java.util.ArrayList.
    http://java.sun.com/docs/books/tutorial/collections/

  • How to open .tab or .txt files in numbers.

    .txt or .tab files grayed out in "open " window

    Hello
    misreading of mine. I read .tab and my brain understood TAB separated.
    Of course TAB separated files must be named xyz.txt
    comma separated files must be named xyz.csv
    Yvan KOENIG (from FRANCE vendredi 15 février 2008 19:25:19)

  • Want to Read the a txt file and put the data into the table colums.

    I have a text file in which data is piped separated and I want to put the data in the table column.
    Eg.
    Text File Column
    First_name|Last_name|address|phone_number
    Database table:
    first_name ,last_name,address,phone_number
    It's very urgent.
    Thanks For your help in advance.
    Himanshu

    Use sqlldr or external file.
    See http://download.oracle.com/docs/cd/E11882_01/server.112/e10701/part_ldr.htm#i436326 for SQL Loader.
    See http://download.oracle.com/docs/cd/E11882_01/server.112/e10595/tables013.htm#ADMIN11705 for External table.

  • I need help for reading from a .txt file.

    My goal in this program is to display the data from the text file to the command prompt. Everything compiles, but its doesnt display the data.
    It probably has to do with my constructer. So help with revising the constructing would be appreciated. I am new to programming by the way.
    import java.util.*;
    import java.io.*;
         class Inventory
         public static void main(String[] args)
              final int MAX = 50;
              InventoryItem[] items = new InventoryItem[MAX];
              StringTokenizer tokenizer;
              String line;
              String name;
              String file = " inventory.txt ";
              int units = 0;
              int count = 0;
              float price;
              try
                   FileReader fr = new FileReader ("inventory.txt");
                   BufferedReader inFile = new BufferedReader(fr);
                   line = inFile.readLine();
                   while (line !=null)
                        tokenizer = new StringTokenizer (line);
                        name = tokenizer.nextToken();
                        try
                             units = Integer.parseInt(tokenizer.nextToken());
                             price = Float.parseFloat(tokenizer.nextToken());
                             items[count++] = new InventoryItem(name, units, price);
                        catch (NumberFormatException exception)
                             System.out.println("error in input.Line ignored:");
                             System.out.println(line);
                        line = inFile.readLine();
                   inFile.close();
                   for (int i = 0; i<count; i++)
                        System.out.println (items);
              catch (IOException exception)
                   System.out.println("The file " + file + "was not found.");
         } //end of main method
    }// end of Inventory class
    public class InventoryItem
         private String name;
         private int units;
         private float price;
         public InventoryItem (String nameOfItem, int numOfUnits, float priceOfItem)
              name = nameOfItem;
              units = numOfUnits;
              price = priceOfItem;

    Use CODE tags
    What's not printing?
                        try
    units =
    its = Integer.parseInt(tokenizer.nextToken());
    price =
    ice = Float.parseFloat(tokenizer.nextToken());
    items[count++] = new InventoryItem(name, units,
    nits, price);
                        catch (NumberFormatException exception)
    System.out.println("error in input.Line <========= THIS ???????
    .Line ignored:");
                             System.out.println(line); <============= AND THIS???
                        line = inFile.readLine();
                   inFile.close();
                   for (int i = 0; i<count; i++)
                        System.out.println (items); <========== THIS IS OK, right?
    If I have correctly indentified your problem, then the reason it's not printing is that your print statements are within a catch block, and evidently your code is not throwing any NumberFormatExceptions

  • Read numbers from a .txt file and display them in a graph

    How can I get Labview 7 to read from a txt. file containing a lot of
    coloumns with different datas? There`s only two of the coloumns that are
    interesting to me, the first, that contains the time of the measuring, and
    one in the middle, that contains the measured temperatures. I want Labview
    to read this datas and display them graphicly.
    Thanks from Stale

    Here's one way.
    You can also use the help-> find examples and search for "text".
    2006 Ultimate LabVIEW G-eek.
    Attachments:
    Graph.vi ‏21 KB

Maybe you are looking for

  • Error in EHP1 Portal Installation

    Dear All, I am facing a weird error while install EHP1 Portal system. When it comes to phase Install Software units, it always fail with the same error. System details are below: System: Netweaver Portal EHP1 System (Usage Type: As Java, EP, EP Core

  • Generate a PS in Indesign CS5 - PPD problem

    I am a little publisher and I migrated to Indesign from Xpress several years ago. I've recently installed the CS5 Premium suite and I'm very upset about the new version of Indesign. I discovered (with my surprise) that in the print window it's imposs

  • Deleting records from child to parent table

    I have ran into a situation where i will have to delete all the records of the child table and then the records of parent table and i was able to write a query to get the column,table both for parent,child and stuck up in deleting them using query an

  • Inaccessible Adobe PDF pack

    I just paid $10 for the Adobe PDF Pack. But it is still unavailable (still asks me to subscribe for $10). How can I solve this or get my $10 back?

  • Disabling while certain apps are running

    Apologies if this has been asked before and answered, but I can't find it anywhere. Is there any way (other than manually turning time machine off in the sys prefs) to get time machine not to do backups when a certain application is running? There ar