Problem with reading from DAT file. FileNotFound exception

Can't seem to find the issue here. Two files, one (listOfHockeyPlayers) reads from a DAT file a list of players. The other (HockeyPlayer) has just the constructor to make a new hockey player from the read data.
import javax.swing.*;
import javax.swing.event.*;
import java.util.*;
import java.awt.*;
import java.io.*;
public class ImportHockeyPlayers
private ArrayList<HockeyPlayer> listOfHockeyPlayers = new ArrayList<HockeyPlayer>();
public ImportHockeyPlayers(String fileName)
  throws FileNotFoundException
  try
   Scanner scan = new Scanner(new File(fileName));
   while (scan.hasNext())
    //Uses all the parameters from the HockeyPlayer constructor
    String firstName = scan.next();
    String lastName = scan.next();
    int num = scan.nextInt();
    String country = scan.next();
    int dob = scan.nextInt();
    String hand = scan.next();
    int playerGoals = scan.nextInt();
    int playerAssists = scan.nextInt();
    int playerPoints = playerGoals + playerAssists;
    //listOfHockeyPlayers.add(new HockeyPlayer(scan.next(),scan.next(),scan.nextInt(),scan.next(),scan.nextInt(),scan.next(),
     //scan.nextInt(),scan.nextInt(),scan.nextInt()));
  catch(FileNotFoundException e)
   throw new FileNotFoundException("File Not Found!");
public String toString()
  String s = "";
  for(int i = 0; i < listOfHockeyPlayers.size(); i++)
   s += listOfHockeyPlayers.get(i);
  return s;
public class HockeyPlayer
private String playerFirstName;
private String playerLastName;
private int playerNum;
private String playerCountry;
private int playerDOB;
private String playerHanded;
private int playerGoals;
private int playerAssists;
private int playerPoints;
public HockeyPlayer(String firstName, String lastName, int num, String country, int DOB,
  String hand, int goals, int assists, int points)
  this.playerFirstName = firstName;
  this.playerLastName = lastName;
  this.playerNum = num;
  this.playerCountry = country;
  this.playerDOB = DOB;
  this.playerHanded = hand;
  this.playerGoals = goals;
  this.playerAssists = assists;
  this.playerPoints = goals + assists;
DAT File
Wayne Gretzky 99 CAN 8/13/87 R 120 222
Joe Sakic 19 CAN 9/30/77 L 123 210These are all in early development, we seem to have the idea down but keep getting the odd FileNotFound exception when making an object of the ImportHockeyPlayers class with the parameter of the DAT file.
We might even be on the wrong track with an easier way to do this. To give you an idea of what we want to do...read from the file and be able to pretty much plug in al lthe players into a GUI with a list of the all the players.
Thanks for your time.

Thanks for the tip on the date format...good to
know.
public static void main(String[] args)
GUI gui = new GUI();
ImportHockeyPlayers ihp = new
ImportHockeyPlayers("HockeyPlayers.dat");
}It's just being called in the main.
Throws this error:
GUI.java:39: unreported exception
java.io.FileNotFoundException; must be caught or
declared to be thrown
ImportHockeyPlayers ihp = new
ImportHockeyPlayers("HockeyPlayers.dat");
^This error is simply telling you that an exception may occur so you must enclose it in a try catch block or change the main method to throw the exception as follows
public static void main(String[] args) throws  
                      java.io.FileNotFoundException {
     GUI gui = new GUI();
     ImportHockeyPlayers ihp = new
     ImportHockeyPlayers("HockeyPlayers.dat");
}or
public static void main(String[] args) {
     GUI gui = new GUI();
     try {
          ImportHockeyPlayers ihp = new
          ImportHockeyPlayers("HockeyPlayers.dat");
     catch (FileNotFoundException e) {
          System.out.println("error, file not found");
}I would reccomend the second approch, it will be more helpful in debugging, also make sure that the capitalization of "HockeyPlayers.dat" is correct
hope that helps

Similar Messages

  • Problem with reading from bin file into Vector

    What am I doing wrong? It works fine to write the vector to the bin file and then read from it. But if I try just to read from the file it wont work.
    Does anybody has any good advice to give when it comes to reading data form a bin file??
    import javax.swing.*;
    import java.util.*;
    import java.io.*;
    class Binaerfil
         public static void main (String [] args) throws IOException, ClassNotFoundException{
              ObjectOutputStream utFil = new ObjectOutputStream (new FileOutputStream("HighScoreLista.bin"));
              int po = 50;
              Spelare s;
              Spelare s1, s2, s3, s4, s5,s6,s7,s8,s9,s10;
              String f�rNamn;
              Vector v = new Vector();
              s1 = new Spelare("Mario", 100);
              s2 = new Spelare("Tobias",90 );
              s3 = new Spelare("Sanja", 80 );
              s4 = new Spelare("Marko", 70 );
              s5 = new Spelare("Sofia", 60 );
              s6 = new Spelare("Kalle", 50 );
              s7 = new Spelare("Lisa", 40 );
              s8 = new Spelare("Pelle", 30 );
              s9 = new Spelare("Olle", 20 );
              s10 = new Spelare("Maria",10 );
              v.add(s1);
              v.add(s2);
              v.add(s3);
              v.add(s4);
              v.add(s5);
              v.add(s6);
              v.add(s7);
              v.add(s8);
              v.add(s9);
              v.add(s10);
              System.out.println ("Before writing to file");
              System.out.println(v);
              //Write to file
              utFil.writeObject (v);
              utFil.close();
         ObjectInputStream inFil = new ObjectInputStream (new FileInputStream("HighScoreLista.bin"));     
              v =(Vector) inFil.readObject();
         System.out.println (v);
              inFil.close();
    }

    Because what you are writing to the file is a vector, that is all you can get out. You are actually reading a single Object from the file which you can cast to a Vector, from which you can access the data stored inside. If you want to read the Spelare instances from the file, you will have to save them individually to the file. You will have to implement Serializable and look up the API to do that.

  • Problem with reading from a file

    `HI,
    i am trying to read from a text file... using following piece of code
    try{               
                   BufferedReader in = new BufferedReader( new FileReader(fileName), 100000);
                   while (in.readLine() != null)
                        temp = in.readLine();
                   in.close();
                   in = null;
                   } catch(Exception e) {System.err.println(e); }          
                   System.out.println(temp);     
    text contains almost 7500 words...
    but when i run this piece of code... output i got is NULL
    ... i don't know what i am doing wrong...
    any suggestions
    <Thanx in advance >

    while (in.readLine() != null)Right here, you are reading in the file, but you don't store the content.
    temp = in.readLine();By the time you reach here, you have already read in the whole file, so there is nothing left to read. That's why temp is assigned null

  • Fpga Simulation from Custom VI'a. Problem with reading TDMS data for simulation.

    Hi there. I am havin a small no Big problem trying to use certein data for simulation purpose. All I/O are set up in custom Via. Everything works fine when it is set up like on a pic.1 Unfortunatly I would like to use certein data writtent to TDMS file. I tried to do it like in PIC2. It works on normal VI'a. It reads the file to array. Unfortunatly I don't know how to make it works in custom via set up for FPGA simulation. I am getting 0.
    PIC.1 Random data...
    PIC.2 Data from a file format.

    oki I managed my self. For some reason I had to skip first number in the array.

  • Problem in reading from the File

    Hi,
    I have a dataset.txt file which is as follows:
    2
    4
    1 2 3 4
    2 3 4 5
    3 4 5 6now that I need the value that is present in the 1st line of the file(ie;2) and value present in the 2nd line of the file(ie;4), upon that i'll be reading the data into an array.
    for this task of mine to accomplish , i'm using the following code
    String line_1;
    String line_2;
              int first_line,second_line;
              DataInputStream dis1 =null;
              DataInputStream dis2 =null;
              System.out.println("Print this");
              try
                   File f1=null;
                   f1 = new File ("dataset.txt");
                   File f2=null;
                  f2 = new File ("dataset.txt");
                 FileInputStream fis1 = new FileInputStream(f1);
                 FileInputStream fis2 = new FileInputStream(f2);
                 dis1 = new DataInputStream(fis1);
                 dis2 = new DataInputStream(fis2);
                           BufferedReader line1 = new BufferedReader(new InputStreamReader(dis1));
                      line_1=line1.readLine();
                      first_line=Integer.parseInt(line_1);
                      System.out.println("Value of First_line is:     "+first_line);
                      BufferedReader line2 = new BufferedReader(new InputStreamReader(dis2));
                      line_2=line2.readLine();
                      second_line=Integer.parseInt(line_2);
                      System.out.println("Value of Second_line is:     "+second_line);
    }//end of try
    catch(Exception e)
    {e.printStackTrace();}The problem here I'm having is, when i'm printing I'm getting the follow result
    Value of First_line is:2
    Value of Second_line is:2Instead of printing the value of Second_line as 4, it is printing 2.
    Why is this happening?
    Any kind of response is appreciated.
    Thanks is advance

    You dont have to make 2 data stream objects of the file.
    To read two lines you can just do with it object
    BufferedReader line1 = new BufferedReader(new InputStreamReader(dis1));and just call readLine( ) method twice
    line_1=line1.readLine();
    line_2=line1.readLine();

  • Problem while reading from text file using JDeveloper 10.1.2

    Hi,
    I am using JDeveloper 10.1.2 for my application. In this, I have one requirement to read some data from a text file. For that, I created a test file and saved along with the java file folder. From there, I am trying to read this file but it says the file not found exception.
    Application is looking the file from another location. "F:\DevSuiteHome_1\jdev\system10.1.2.1.0.1913\oc4j-config"
    But, I want to read it from my home folder. How is it possible to read from that location?
    Regards,
    Joby Joseph

    HI,
    Check followings will useful
    How to read .txt file from adfLib jar at model layer using relative path
    Accessing physical/relative path from Bean

  • Problem using read from spreadsheet file and polar plotting

    Hi to all labview users,
    i am a beginner in labview and i am trying to do a polar plot.
    i read the polar plotting example in labview and it was straightforward.
    I used "write to spreadsheet file" to gather data.
    and they are in the following format
    13  10
    4  20
    8 30
    ....etc
    now. i tried using "read from spreadfile" to get the data into a array, then using "array to cluster" to convert the array into cluster, so i could connect it to the polar plot block
    however, it kept saying i couldnt connect that way, because polar plot uses 1-d array with cluster of 2 element and my source is a cluster of 9 elements....
    but doesnt the "read from spreadfile" block give me a 1-d array? and where does that 9 come from? i only have 3 rows and 2 columns in my data file....
    any guidance would be greatly appreciated.
    thx alot
    Happy guy
    ~ currently final year undergraduate in Electrical Engr. Graduating soon! Yes!
    ~ currently looking for jobs : any position related to engineering, labview, programming, tech support would be great.
    ~ humber learner of LabVIEW lvl: beginner-intermediate

    Helllo,
    I've made an example to try to help you  with that question.
    Notes:
     - the file must have values separeted by tab
     - reading the values from file as you mentioned using "read from spreadfile" you'll get a 2D array and not 1D;
    Software developer
    www.mcm-electronics.com
    PS: Don't forget to rate a good anwser ; )
    Currently using Labview 2011
    PORTUGAL
    Attachments:
    Read Table and plot polar graph.vi ‏26 KB
    teste.txt ‏1 KB

  • Problem with a corrupt data file

    I have a user who has a corrupt outlook profile, new updates to the exchange servers are not propagating through to her account. I have created her a new profile in outlook which fixes this issue but unfortunately throws up another.
    Using her old corrupt profile she has access to her data files of which there are seven. using her new profile these data files although saved as .PST are not recognised by outlook, this sais to me that they also are corrupt. I have tried running SCANPST.exe
    and that cannot find the data files either, I have also tried creating a new data file and copying the folders into it without success. Is there some trick I am missing to get these to work with her new profile, they work fine with her old profile which means
    they cant be to badly corrupted.
    Any advice at this point is most welcome
    cheers
    Paul

    Glad to hear that. And thank you for sharing your experience here. It will be helpful for other community members who have similar problems.
    Cheers,
    Steve Fan
    TechNet Community Support

  • Problem in reading from excel file with my requirement

    Hi,
    Below is my input excel file format
    A    XXX
    B    XXX
    C    XXX
    D    E   F   G  H  I    J  K  L  M  N
    XX   XX  XX  XX.........................XX
    All the A...N are headings and XX's are values.
    How should I define an internal table for this requirement. I am using FM TEXT_CONVERT_XLS_TO_SAP to read input file.
    Please let me know the correct way to define internal table for the above file format.
    Regards,
    Cheritha

    Hello Cheritha,
    Your final internal table(t_final) should have all the fields viz. A, B, C, D etc.
    You need to read the file to an internal table say t_data. In the internal table t_data, the field values will be each row in this internal table.
    So you need to loop on t_data and based on the field name assign it to the corresponding field in the internal table t_final.
    Hope this is clear if any clarification please do reply
    Regards
    Farzan

  • Problems with reading Interface data

    Hi all,
    I try to fill an interactive form with the data I filled into my interface.
    I have no problems to include data to a textbox, but when I try to change the data, the box leaves empty.
    Also I must get data from the interface in background to compare them, but I can't find any possibility to read data from the interface to a variable.
    How can I solve that problems? Any ideas?
    Greets Andreas
    EDIT:
    I use Adobe Livecycle Designer with APAB (Transaction: SFP)

    Hi Maksim,
    To understand if you have set correct regional settings for you SAP BPC server you have to check the follow keys:
    HKEY_USERS\.Default\Control Panel \ International
    HKEY_USERS\S-1-5-18\Control Panel \ International
    HKEY_USERS\S-1-5-19\Control Panel \ International
    HKEY_USERS\S-1-5-20\Control Panel \ International
    HKEY_USERS\S-1-5-21\Control Panel \ International
    HKEY_USERS\S-1-5-21.....\Control Panel \ International
    should have all the keys for English US.
    Kind Regards
    Sorin Radulescu

  • Problems with prints from RAW files

    I wonder if someone could shed some light on this problem. I uploaded some photos to Kodak through iPhoto, some were JPEG's from my old Canon Powershot and some were RAW files from my new Nikon D40. The images on my monitor from the RAW files from the D40 were great with very vivid colors and I was looking forward to my first prints from the D40. When I received the prints the photos from the old Power shot looked good but the D40 looked terrible. The prints were all washed out and very dull, the strange thing was that there was one photo that was taken with the D40 which was edited and that came out as a good print and seemed to be a JPEG. I guess its something to do with the upload of RAW files, should I be shooting in JPEG ?. I thought that iPhoto uploaded JPEG's
    Thank you in advance

    Printed RAW files will always look unsaturated or "dull" until processed and saved as a jpeg or tiff files. Think of RAW/NEF as a means of preserving ALL the available information to later "develop" a final image to be saved as tiff or jpeg for publication. Shooting in Large Fine JPEG mode will yield great results for print and web publishing, and also leave more room on your memory card and computer drive to make more great photos
    Nikon D70 & D200; TiBook 1Ghz; MacBook 2Ghz; Dual 1.8Ghz PowerMac G5; 20" Cinema Display   Mac OS X (10.3.9)   additional 300 GB internal; 160GB and 300GB externals; 10GB, 40GB, 60GB iPods

  • Problems with reading a pdf-file using Safari/Adobe Acrobat Pro

    Using Adobe Acrobat Pro 9.5.5. and Safari in Snow Leopard I open the pdf-file of  http://dare.uva.nl/document/505726 and small boxes appear in the text f.i. on page 70, 74, on the last page etc.
    I don't know why those small boxes appear only on my MacBook Pro with the installed software and others don't read a corrupt text. If I click in den pdf-file on the right side of the mouse and choose "open with Adobe Acrobat Pro" the pdf-file opens correctly (without small boxes)!

    As you discovered, Adobe Acrobat/Pro/Reader v.9 will crash for all managed user accounts that store their home folders on the server because it has "difficulty" reading and writing to a folder across a network, which is why it crashes shortly after it launches.
    HOWEVER, there is hope. All you need to do is tell Adobe to write all of its files to the local drive rather than the home folder on the sharepoint, as follows:
    While logged into your network-user account:
    1. Go to the "Shared" folder on the local drive. (Local HD > Users > Shared)
    2. Create a new folder named "9.0_x86" if you have an Intel or "9.0_ppc" if you have a PPC (without the quotes for either case). You will have to authenticate as an Administrator.
    3. Go to the Acrobat folder within the user's Application Support and delete the folder in it.
    (Home > Library > Application Support > Adobe > Acrobat > 9.0_x86 or 9.0_ppc)
    4. Open/launch the Terminal application found within the Utilities folder on you Mac.
    (Applications > Utilities > Terminal.app)
    5. In Terminal, enter the 1st command for Intel or the 2nd for PPC:
    ln -s /Users/Shared/9.0_x86 ~/Library/Application \Support/Adobe/Acrobat/9.0_x86
    OR
    ln -s /Users/Shared/9.0_ppc ~/Library/Application \Support/Adobe/Acrobat/9.0_ppc
    Adobe Acrobat 9 should now work properly. You may get the "quit unexpectedly" error message the first time you quit the application, but should only happen the one time.
    On a side note, the print spool is slow when printing very large multi-paged PDFs.
    This is a fix I found in 2009 by Dennis, can't remember where though.
    Message was edited by: Gabriel Prime

  • Read from text file takes very long after the first time

    Dear LabVIEW experts,
    I'm having a problem with read from text file. I'm trying to read only every nth line of a file for a preview with this sub vi:
    I seems to work well the first time I do it. The loop takes almost no time to execute an iteration.
    Then when I load the same file again with exactly the same settings one iteration takes around 50ms.
    Subsequent attempts seem to always take the longer execution time.
    Only when I restart the calling vi it will be quick for one file.
    When executing the sub vi alone it is always quick, but I don't see how the main vi (too complex to post here) could obstruct the execution of the sub vi.
    I don't have a the file opened elsewhere in the main vi, I don't use too much memory...
    Right now I don't now where to look. Does anyone have an idea?
    Regards
    Florian
    Solved!
    Go to Solution.

    I don't know the LabVIEW internals here, but I would think that it is quite possible that closing a file opened for read/write access writes a new copy of the file to disk, or at least checks the file in order to make sure a new file does not have to be written.
    Therefore, if your main VI calls this subVI sequentially (you don't give any information about the place of this subVI in the main VI), you are actually looking at a close (check/write) -> open operation for any time you call it, as opposed to a simple open operation the first time. If you were to open the file for simple read access (since that's all you do), it should work fast every time because there is no need to check to see if it has changed.
    Cameron
    To err is human, but to really foul it up requires a computer.
    The optimist believes we are in the best of all possible worlds - the pessimist fears this is true.
    Profanity is the one language all programmers know best.
    An expert is someone who has made all the possible mistakes.
    To learn something about LabVIEW at no extra cost, work the online LabVIEW tutorial(s):
    LabVIEW Unit 1 - Getting Started
    Learn to Use LabVIEW with MyDAQ

  • Problem with reading special char from file

    Hello Oracle community,
    Got a problem when reading from a file. I am using a croatian keyboard and trying to read special charachters (ČĆŽŠĐ) from a file.
    declare
      l_file utl_file.file_type;
      s varchar2(200);
    begin
      l_file := utl_file.fopen('test_dir', 'test.txt', 'R');
      loop
        utl_file.get_line(l_file, s);
        dbms_output.put_line(s);
      end loop;
    exception
      when no_data_found then
        utl_file.fclose(l_file);
    end;But I keep getting this in dbms_output: ČƎŠĐ. For some reason it keeps skipping 2 chars Š and Ž. If I try to insert or update data the values are show correctly. What could be the cause of such a problem?
    Best regards,
    Igor

    Hi Igor,
    Looks like a NLS_LANGUAGE issue. Check the following threads:
    UTL_FILE and NLS_LANG setting
    Re: Arabic characters not displaying in Forms
    Regards,
    Sujoy

  • Read from spreadsheet file

    Hi! I am a beginner labview user and I have a problem reading data from a
    ..xls file. I have written in columns the data that i want to present in a
    waveform graph through labview. I give the path to the Read From Spreadsheet
    File tool and i connect a true constant in the "transpose" terminal. The Run
    button shows me no error but all I get in my waveform graph is a x-axis
    line. Could someone help me? Thanx

    You say that you want to read data from a .xls file. You use Read From Spreadsheet File to get the data into LV.
    You have mixed some things. A .xls file is NOT a spreadsheet file. It is a file which could be read by MS Excel and some other tools which have import filters for this file. Read from Spreadsheet File is not such a filter.
    A spreadsheet file in the context of LV is a text file where the cells of a row are separeted by a tab and the rows are separated by a end of line.
    A save thing is use Active-X automation to communicate with MS Excel. Let it load the file and read out the cells. The are examples in LV help and in the dev zone. You must have installed and licenced MS Ecxel on your target machine. Maybe someone has written such a fil
    ter for LV but I don't know it.
    The other way will only work if you use US local settings and the data is in one worksheet. Save the file with the extention .txt. So Excel will generate a text file of the correct format. Excel will use the regional settings of your machine. You can read in this file with Read From Spreadsheet File. Unfortunatly this will use fixed settings which are the same as for US regional settings.
    Waldemar
    Waldemar
    Using 7.1.1, 8.5.1, 8.6.1, 2009 on XP and RT
    Don't forget to give Kudos to good answers and/or questions

Maybe you are looking for

  • Officejet pro 8625 will not print

    Just purchased this printer. Scanning, faxing, email to printer all works fine. When I try to print any document it spools then deletes the print job as if done but doesn't print. I have uninstalled/reinstalled, run the diagnostic test and nothing is

  • Do not import duplicates not working

    How can I import only new photos from memory card? the do not import duplicates checkmark  does not work anymore.

  • AR Tax posting for China or Shanghai invoice

    Dear All, According to the tax law in China, AR Tax posting in China should not be put on account of the Tax Receivale. Instead, customer should pay full amount of document, and then AR Tax poating should be billed on account of Tax Payable. The curr

  • N70 - what is this icon

    in this screen capture see http://www.web0.co.uk/images/asstd/screen.jpg I have outlined in blue an icon that has started appearing on screen. Seeing as how the manual for the n70 is one of the most poorly written, inorganised, and unintuitive consum

  • Xpath Namespace problem

    Hi, I'm facing a problem while reading an xpath element which has namespace attached. The xml document is as follows <ns0:_root  xmlns:ns0="http://www.oracle.bt.bp.osm/GPRLN"> <ns0:Port_and_Routing_Details_g> <ns0:Action_Code> <ns0:Code1>Add</ns0:Cod