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/

Similar Messages

  • 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

  • Address Book NOT accepting csv.txt file as import from EARTHLINK web mail

    Greetings. Unsuccessful thus far in importing e-addresses from Earthlink Web Mail to MAC Address Book. Found preferences and saved Earthlink addresses as csv.txt file but AB rejected as not true csv. Apple suggested conversion to V cards but could not find that option in Earthlink-ville. Perused Allan's post on synching with Total Access but fear accidentally installing stuff on my MACbook Pro from that application that is unneccessary or will screw up my new MAC world. Although in the long run, having Web mail back up my MAC makes sense. (Work and husband remain PC/ XP.)
    Any solutions you can offer will be much appreciated.
    Macbook Pro   Mac OS X (10.4.9)  

    Thanks again. Okay, I pasted a portion of the csv file . I might be mistaken here, but I don't think these are V card format and perhaps converting them to V cards is what I'd have to do. But I would need pretty explicit directions.
    Regards,
    Andrea
    "First Name","Last Name","Middle Name","Name","Nickname","E-mail Address","E-mail 2 Address","E-mail 3 Address","Home Street","Home City","Home Postal Code","Home State","Home Country/Region","Home Phone","Home Fax","Mobile Phone","Personal Web Page","Business Street","Business City","Business Postal Code","Business State","Business Country/Region","Business Web Page","Business Phone","Business Fax","Pager","Company","Job Title","Department","Office Location","Notes"
    "[email protected]","","","[email protected]","","[email protected]","","","","" ,"","","","","","","","","","","","","","","","","","","","",""
    "Thomas","Brown","","Thomas Brown","","[email protected]","","","","","","","","","","","","","","",""," ","","","","","","","","",""
    "Bob","Nash","","Bob Nash","","[email protected]","","","","","","","","","","","","","","","", "","","","","","","","","",""

  • What is the best way to export a .csv/.txt file to a MS Windows shared folder via a scheduled job?

    What is the best way to export a .csv/.txt file to a MS Windows shared folder, when the export process is a scheduled job?

    You can't directly, as scheduled jobs can only export to server-side data stores, which can only write to the landing area. You'll need to use an external script (e.g. batch file) to move the file from the landingarea after export. You can use an external task in the scheduled job to invoke the script.
    regards,
    Nick

  • 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.

  • 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]

  • Help.  Does use of .txt file make sense or code directly into an ArrayList

    I am writing my first program and I want to put a series of information in various .txt files. This is because I will have a lot of different objects that I will create that will needed to be iterated over (most of the objects are similar in many ways). It seemed to me that a .txt file would be better than writing the items directly in an arraylist (if you know what i mean). What do you think?
    There will be 7 different objects that will be iterated over (and there will be 12 other objects doing other things as well, they will not be in .txt format), and I thought instead of having to maintain it through the actual code, I would just have .txt files that I create in notepad or something so that when I need to make changes to one of the 7 objects I only have to get the .txt file instead of having to wade through the code to find that object.
    Does this make sense?
    It seems that I will now have to do a lot of I / O to make it work, so now I am thinking maybe it is better to simply use the arrylist. Is there a benefit of one over the other in this circumstance?
    Also one of the objects has jpeg files that will need to be iterated over. Actually for these I will put them in an array list, because I can't seem to figure out yet how to get an image and the information about the image to display within I/O (like CD covers and their titles).
    Thank you for any help and suggestions I feel a little overwhelmed, but hopeful, with you kind folks.
    Peace
    NB I know that I am not using the correct terminology, but I hope that you can understand what I mean.
    Message was edited by:
    peacerosetx

    I am writing my first program and I want to put a
    series of information in various .txt files. Thisis
    because I will have a lot of different objects thatI
    will create that will needed to be iterated over
    (most of the objects are similar in many ways). It
    seemed to me that a .txt file would be better than
    writing the items directly in an arraylist (if you
    know what i mean). What do you think? I think I do not know what you mean. I also think
    that ArrayLists and files shouldn't replace eachI am going to use an ArrayList. Merci
    other.
    There will be 7 different objects that will be
    iterated over (and there will be 12 other objects
    doing other things as well, they will not be in.txt
    format),Seven objects? Twelve objects? Huh? Why not use
    arrays? And how do you get an object into a text
    file?
    and I thought instead of having to maintain
    it through the actual code, I would just have .txt
    files that I create in notepad or something sothat
    when I need to make changes to one of the 7 objectsI
    only have to get the .txt file instead of havingto
    wade through the code to find that object.
    Does this make sense? Your description? Not to me.
    It seems that I will now have to do a lot of I / Oto
    make it work, so now I am thinking maybe it isbetter
    to simply use the arrylist. Is there a benefit of
    one over the other in this circumstance? Uh, ArrayList is way faster and much easier
    modifyable.
    Also one of the objects has jpeg files that willneed
    to be iterated over. Actually for these I will put
    them in an array list, because I can't seem tofigure
    out yet how to get an image and the informationabout
    the image to display within I/O (like CD coversand
    their titles). "Display within I/O"? This makes no sense.
    NB I know that I am not using the correct
    terminology, but I hope that you can understandwhat
    I mean.If you're not using the correct terminology, there's
    no chance for us to understand you. If you say
    "objects" but mean "classes", then say classes.

  • 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.

  • 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 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

  • 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"));
    }

  • 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

  • Help with reading in a text file and arrays

    I need to read in a text file with info like this for example
    dave
    martha
    dave
    billy
    I can read the information into an array and display the names but what I need to do is display how many times the same name is in the file for example the output should be
    dave 2
    martha 1
    billy 1
    How can I accomplish this? Would I use a Compareto Method to find
    duplicate names?

    Hi,
    I would recommend storing them in a Hashtable.. something like this:
    Hashtable names = new Hashtable() ;
    String s ;
    while( ( s = bufferedReader.readLine() ) != null ) {
        if ( names.contains( s ) ) {
           names.put( s , new Integer( names.get(s)+1 ) ) ;
        else {
           names.put( s , new Integer( 1 ) ) ;
    }Then the hashtable will contain a set of keys and values, which are the names and counts respectively.
    Kenny

  • Need Help using OpenText Methord to read a CSV formmated file into an excel spreadsheet

    I am trying to load a csv into excel with formated columns, the 4th column is alphanumeric but after loading the values in the four column the column is define as general and it drops the leading zeros on values that have the leading zeros
    i can not use a sub string to preload the zeros due to varing length and format the csv file has them correctly anybody have a solution on how to correct?
    the VBScript looks like;
    Set objExcel = CreateObject("Excel.application")
    Const xlDelimited  = 1
    Const xlGeneralFormat = 1
    Const xlTextFormat = 2
    oFile = "I:/temp/MEMAPRPT3P 2014-08-04.csv"
    wfile = "I:/temp/MEMAPRPT3P 2014-08-04"
    filetime = "_2015_01_20_10_28_00"
    tagname = "sample"
    objExcel.application.visible=false
    objExcel.application.displayalerts=false
    objExcel.Workbooks.OpenText Filename, , 1, 1, , False, False, False, True, False, , ,Array(Array(1, xlTextFormat), Array(2, xlTextFormat), Array(3, xlTextFormat), Array(4, xlTextFormat))
    Set objExcelBook = objExcel.ActiveWorkBook
    Saveasfile = trim(wfile) & trim(filetime) & ".xlsx"
    objExcelBook.SaveAs Saveasfile, 51
    objExcel.Application.Quit
    objExcel.Quit  
    Set objExcel = Nothing
    Set objExcelBook = Nothing
    The csv data look like"HEDA","Fred","Detroat","0598""SDRA","Steve","Jericho","Q23456""ADAS","Tim","Home","000892356"

    i can not use a sub string to preload the zeros due to varing length and format the csv file has them correctly anybody have a solution on how to correct?
    The issue is that the cell isn't formatted as text, that's a bug within OpenText.
    You can use a query table instead and emulate OpenText. The benefit is that you can import the data in the current file.
    Andreas.
    Sub Test()
    Dim FName As String
    Dim Q As QueryTable
    FName = "C:\Users\Killer\Documents\test.csv"
    'Add a new sheet after the current sheet
    Worksheets.Add After:=Sheets(ActiveSheet.Index)
    'Add a query table
    Set Q = ActiveSheet.QueryTables.Add( _
    Connection:="TEXT;" & FName, Destination:=Range("$A$1"))
    With Q
    'Setup the importsettings
    .TextFileCommaDelimiter = True
    .TextFileTextQualifier = xlTextQualifierDoubleQuote
    .TextFileColumnDataTypes = Array(xlTextFormat, xlTextFormat, xlTextFormat, xlTextFormat)
    'Import the data
    .Refresh BackgroundQuery:=False
    'Delete the query table (we don't need a permanent link to the file)
    .Delete
    End With
    End Sub

Maybe you are looking for

  • Firefox will not start at all

    New versions of Firefox will not start and only bring up the crash reporter. I've tried starting in safe mode, I've deleted/created new Profiles and I've uninstalled/installed Firefox over and over. I can still download 28.0 and it has no problem ope

  • [Help] Windows 8.1 - Windows Update Cleanup not clearing

    Hi guys, I've been troubleshooting my MSI Laptop GE40 for quite awhile now, but I am just unable to find a solution online. My laptop is running Windows 8.1, I was doing some cleaning up for my laptop using Disk Cleanup. After running Disk Cleanup (W

  • Problems with an external hard drive (not Time Machine related)

    First, I'll clarify that I'm using an internal hard drive inside an external enclosure, incase that makes a difference to my problem. I got this drive to store my music on, since I've run out of room on my main hard drive. I've transfered all my musi

  • Message problem in BDC

    Hi All, I am doing a bdc program inside  RFC-FM.in which i need  to do a posting in FI and return the document number via the export parameter of the RFC-FM.when the function module is tested in foreground its giving me the document number via the su

  • How to create users in Fusion MiddleWare Control.

    Hi, Can someone guide me on how can we create readonly users for FMW control. I need to know this as the application support team would have to login to the console to check the status of the BPEL instances. This user should not have any access other