Having problems with File IO, not sure what im doing or lack thereof.

This is my code, basically I create a class which reads data from a .dat file which contains names and salarys, based on a question i found on a forum online, anyways I first created the .dat, now I need to create a class which takes the .dat file and writes it to a .txt file...he is my code I keep getting an EOFException which I have read in the docs is caused by an unexpected stop in reading of the data from file. Any assistance with regards to this problem would be much appriciated. Here is my code:
import java.io.*;
public class EmployeeRead implements Serializable{
     public static void main(String[] args){
     String inFile = null;
     String outFile = null;
     if (args.length<2) {
     System.out.println("You must specify two input files and one output file.");
     try {
     InputStreamReader reader = new InputStreamReader(System.in);
     BufferedReader console = new BufferedReader(reader);
     System.out.print("Please type the name of the .dat file: ");
     inFile = console.readLine();
     System.out.print("Please type the name for the .txt file (Output): ");
     outFile = console.readLine();
     catch(IOException e) {
          System.err.println("Problem with input: " + e);
     System.exit(1);
     else {
     inFile = args[0];
     outFile = args[1];
     try {
     //inFileReader = new ObjectInputStream(inFile);
     //inFileBuffered = new BufferedReader(inFileReader);
     //ObjectInputStream inFileReader = null;
     //BufferedReader inFileBuffered = null;
     //Input Streams:
          FileInputStream obj = new FileInputStream(inFile);
          ObjectInputStream in = new ObjectInputStream(obj);
          //output stream:
          FileWriter out = new FileWriter(outFile);
     String name = null;
     Double salary = 0.0;
     Employee temp = (Employee)in.readObject();
     Class nameClass = temp.getClass();
     temp = new Employee("SallyJones", 23456);
     while(temp != null){
          name = (String)temp.getName();
          salary = (Double)temp.getSalary();
          out.write(name + " - " + salary);
          temp = (Employee)in.readObject();
          catch(FileNotFoundException e){
          System.err.println("File not found: " + e.toString());
          catch(IOException e){
               System.err.println("Error with file: " + e.toString());
               e.printStackTrace();
          catch(IndexOutOfBoundsException e){
               System.err.println("Index is out of Bounds: " + e.toString());
               e.printStackTrace();
          catch(NullPointerException e){
               System.err.println("Error with String(NullPointerException):" + e);
               e.printStackTrace();
          catch(ClassNotFoundException e){
               System.err.println("Error with Class: " + e);
               e.printStackTrace();
}

Sorry, I was unaware of the code function. My Bad, here is the formatted code:
import java.io.*;
public class EmployeeRead implements Serializable{
     public static void main(String[] args){
         String inFile = null;
         String outFile = null;
          if (args.length<2) {
              System.out.println("You must specify two input files and one output file.");
              try {
                 InputStreamReader reader = new InputStreamReader(System.in);
                 BufferedReader console = new BufferedReader(reader);
                 System.out.print("Please type the name of the .dat file: ");
                 inFile = console.readLine();
                 System.out.print("Please type the name for the .txt file (Output): ");
                 outFile = console.readLine();
              catch(IOException e) {
                      System.err.println("Problem with input: " + e);
                 System.exit(1);
           else {
              inFile = args[0];
              outFile = args[1];
           try {
             //inFileReader = new ObjectInputStream(inFile);
              //inFileBuffered = new BufferedReader(inFileReader);
              //ObjectInputStream inFileReader = null;
               //BufferedReader inFileBuffered = null;
              //Input Streams:
               FileInputStream obj = new FileInputStream(inFile);
               ObjectInputStream in = new ObjectInputStream(obj);
                //output stream:
                FileWriter out = new FileWriter(outFile);
              String name = null;
              Double salary = 0.0;
              Employee temp = (Employee)in.readObject();
              Class nameClass = temp.getClass();
              temp = new Employee("SallyJones", 23456);
              while(temp != null){
                  name = (String)temp.getName();
                  salary = (Double)temp.getSalary();
                    out.write(name + " - " + salary);
                   temp = (Employee)in.readObject();
          catch(FileNotFoundException e){
          System.err.println("File not found: " + e.toString());
          catch(IOException e){
               System.err.println("Error with file: " + e.toString());
               e.printStackTrace();
          catch(IndexOutOfBoundsException e){
               System.err.println("Index is out of Bounds: " + e.toString());
               e.printStackTrace();
          catch(NullPointerException e){
               System.err.println("Error with String(NullPointerException):" + e);
               e.printStackTrace();
          catch(ClassNotFoundException e){
               System.err.println("Error with Class: " + e);
               e.printStackTrace();
}

Similar Messages

  • I received a message about having too many contacts?  Not sure what this means, didn't know there limitations on contacts.  Can you tell me about fixing this problem?

    I received a message about having too many contacts?  Not sure what this means, didn't know there limitations on contacts.  Can you tell me about fixing this problem?

    What were you doing when you received the message?
    I have seen reports on these forums where there is a limit to how many contacts you can have in the "to" field of a text message. That is the only thing I can think of where someone has reported getting a warning about too many contacts.

  • Slow Preformance on HyperV VM's with IIS. Not sure what to change.

    Slow Preformance on HyperV VM's with IIS. Not sure what to change. Doesnt apear to be a Disc I/O issue. Seams to really on happen on VM's that are hosting a mostly static Intranet page. Also same thing happens on another VM that hosts an Apache site. both
    are not very large and VM's run on a Local storage space seperate from the OS and good I/O speed. Host Server gets good network speeds. I have the Host and the VM fully updated.
    Host Server is Windows 2012 and Hosts are Windows 2008r2
    I've gone thur the Hyper V Preformace Blogs and tried to apply all the hot fixes. but most I downloaded said it did not apply to our machine. So Not sure what the issue is.
    Bizquick

    Hi Bizquick,
    >> I did that and Step 4 if thats the case just a few minutes ago on one of the Host's I think I started to see an improvement. But not sure yet. Going to need more testing.
    Has the problem has been solved by disable offloads ?
    Best Regards
    Elton Ji
    We
    are trying to better understand customer views on social support experience, so your participation in this
    interview project would be greatly appreciated if you have time.
    Thanks for helping make community forums a great place.

  • Problem with file descriptors not released by JMF

    Hi,
    I have a problem with file descriptors not released by JMF. My application opens a video file, creates a DataSource and a DataProcessor and the video frames generated are transmitted using the RTP protocol. Once video transmission ends up, if we stop and close the DataProcessor associated to the DataSource, the file descriptor identifying the video file is not released (checkable through /proc/pid/fd). If we repeat this processing once and again, the process reaches the maximum number of file descriptors allowed by the operating system.
    The same problem has been reproduced with JMF-2.1.1e-Linux in several environments:
    - Red Hat 7.3, Fedora Core 4
    - jdk1.5.0_04, j2re1.4.2, j2sdk1.4.2, Blackdown Java
    This is part of the source code:
    // video.avi with tracks audio(PCMU) and video(H263)
    String url="video.avi";
    if ((ml = new MediaLocator(url)) == null) {
    Logger.log(ambito,refTrazas+"Cannot build media locator from: " + url);
    try {
    // Create a DataSource given the media locator.
    Logger.log(ambito,refTrazas+"Creating JMF data source");
    try
    ds = Manager.createDataSource(ml);
    catch (Exception e) {
    Logger.log(ambito,refTrazas+"Cannot create DataSource from: " + ml);
    return 1;
    p = Manager.createProcessor(ds);
    } catch (Exception e) {
    Logger.log(ambito,refTrazas+"Failed to create a processor from the given url: " + e);
    return 1;
    } // end try-catch
    p.addControllerListener(this);
    Logger.log(ambito,refTrazas+"Configure Processor.");
    // Put the Processor into configured state.
    p.configure();
    if (!waitForState(p.Configured))
    Logger.log(ambito,refTrazas+"Failed to configure the processor.");
    p.close();
    p=null;
    return 1;
    Logger.log(ambito,refTrazas+"Configured Processor OK.");
    // So I can use it as a player.
    p.setContentDescriptor(new FileTypeDescriptor(FileTypeDescriptor.RAW_RTP));
    // videoTrack: track control for the video track
    DrawFrame draw= new DrawFrame(this);
    // Instantiate and set the frame access codec to the data flow path.
    try {
    Codec codec[] = {
    draw,
    new com.sun.media.codec.video.colorspace.JavaRGBToYUV(),
    new com.ibm.media.codec.video.h263.NativeEncoder()};
    videoTrack.setCodecChain(codec);
    } catch (UnsupportedPlugInException e) {
    Logger.log(ambito,refTrazas+"The processor does not support effects.");
    } // end try-catch CodecChain creation
    p.realize();
    if (!waitForState(p.Realized))
    Logger.log(ambito,refTrazas+"Failed to realize the processor.");
    return 1;
    Logger.log(ambito,refTrazas+"realized processor OK.");
    /* After realize processor: THESE LINES OF SOURCE CODE DOES NOT RELEASE ITS FILE DESCRIPTOR !!!!!
    p.stop();
    p.deallocate();
    p.close();
    return 0;
    // It continues up to the end of the transmission, properly drawing each video frame and transmit them
    Logger.log(ambito,refTrazas+" Create Transmit.");
    try {
    int result = createTransmitter();
    } catch (Exception e) {
    Logger.log(ambito,refTrazas+"Error Create Transmitter.");
    return 1;
    } // end try-catch transmitter
    Logger.log(ambito,refTrazas+"Start Procesor.");
    // Start the processor.
    p.start();
    return 0;
    } // end of main code
    * stop when event "EndOfMediaEvent"
    public int stop () {
    try {   
    /* THIS PIECE OF CODE AND VARIATIONS HAVE BEEN TESTED
    AND THE FILE DESCRIPTOR IS NEVER RELEASED */
    p.stop();
    p.deallocate();
    p.close();
    p= null;
    for (int i = 0; i < rtpMgrs.length; i++)
    if (rtpMgrs==null) continue;
    Logger.log(ambito, refTrazas + "removeTargets;");
    rtpMgrs[i].removeTargets( "Session ended.");
    rtpMgrs[i].dispose();
    rtpMgrs[i]=null;
    } catch (Exception e) {
    Logger.log(ambito,refTrazas+"Error Stoping:"+e);
    return 1;
    return 0;
    } // end of stop()
    * Controller Listener.
    public void controllerUpdate(ControllerEvent evt) {
    Logger.log(ambito,refTrazas+"\nControllerEvent."+evt.toString());
    if (evt instanceof ConfigureCompleteEvent ||
    evt instanceof RealizeCompleteEvent ||
    evt instanceof PrefetchCompleteEvent) {
    synchronized (waitSync) {
    stateTransitionOK = true;
    waitSync.notifyAll();
    } else if (evt instanceof ResourceUnavailableEvent) {
    synchronized (waitSync) {
    stateTransitionOK = false;
    waitSync.notifyAll();
    } else if (evt instanceof EndOfMediaEvent) {
    Logger.log(ambito,refTrazas+"\nEvento EndOfMediaEvent.");
    this.stop();
    else if (evt instanceof ControllerClosedEvent)
    Logger.log(ambito,refTrazas+"\nEvent ControllerClosedEvent");
    close = true;
    waitSync.notifyAll();
    else if (evt instanceof StopByRequestEvent)
    Logger.log(ambito,refTrazas+"\nEvent StopByRequestEvent");
    stop =true;
    waitSync.notifyAll();
    Many thanks.

    Its a bug on H263, if you test it without h263 track or with other video codec, the release will be ok.
    You can try to use a not-Sun h263 codec like the one from fobs or jffmpeg projects.

  • HT5047 Having problem with the iOS7 verifying update what should I do?

    Having problem with the iOS7 verifying update what should I do?

    Several other users have reported this same problem. Unplug the charger and then replug. It should resume to 100%.
     Cheers, Tom

  • Anyone having problem with iphone getting not delivered message after sending picture and it really is getting delivered to recipient.

    Anyone having problem with iphone getting a not delivered message after sending pic and it really is getting delivered to recipient.

    Same problem here with and I've done everything shy of a total reset which I also find unacceptable. This problem exists on all iMessage platforms (iPhone, iPad, and Mac) so I don't see how restoring my iPhone would help the problem.

  • Am having problem with my iphone4s not syncing with my iPad

    Am having problem with my iPhone 4s calendar events showing up on my iPad .  Have turned calendar off &amp; on in both devices, to no avail

    On the iPhone, check Settings>Mail,Contacts,Calendars>Default Calendar.  Here be sure you have selected the calendar listed under your iCloud account name as your default.  If you haven't, change this, then enter a new event on the phone's calendar and see if it syncs to the iPad now.

  • I am having problem with my imessages not going through

    I am having problems with my tx messages not going through.  some do and some don't

    Do you mean after a phone update? Do you mean just at home? Does it happen everywhere?  Do you have wifi turned on? If its on and your not connecting just clear out the connections (forget) then reset up the connections and see if that helps.  Did you get a Jelly Bean update? Many people have had wifi connections issues because your router is either outdated and not supported with the new os, or it needs a firmware update.  Post back with more information.

  • Having problems with adobe flash player..what do i do!! mouse isn't working.. just installed lion

    having problems with adobe flash player mouse wont work with it?

    Can you post a screenshot of such a request?
    I believe that it is not Adobe or Flash Player doing this, but so far none of the other users who made similar complaints have posted a screenshot.

  • We are still having problems with the "Could not initialize the application's security component" error message after performing suggested fixes?

    We have been attempting to resolve this error in our Lab Environment with FireFox version 14.0.1. The application has been virtually installed in our PC environment, running WIN 7 and launches without error for most users. When performing the suggest "fixes" at http://support.mozilla.org/en-US/kb/couldnt-initialize-applications-security-component we found:
    1. There is adequate hard drive space
    2. Permissions are set correctly.
    3. Once the "Cert8" file is deleted it does not regenerate upon logging out and relaunching Firefox. Not sure why this occurs.
    4. Could not create a new profile since these rights are not extended to users in the lab environment.
    Is anyone using Firefox in a similar lab environment, having this same issue and been able to resolve the problem? Does version 15.0.1 address this problem and provide a fix?

    Try to remove or rename the secmod.db (secmod.db.old) file in the Firefox Profile Folder.
    If that didn't help then remove or rename cert8.db (cert8.db.old) as well.
    You can use this button to go to the Firefox profile folder:
    *Help > Troubleshooting Information > Profile Directory: Show Folder
    *http://kb.mozillazine.org/Profile_folder_-_Firefox
    * C:\Users\&lt;user&gt;\AppData\Roaming\Mozilla\Firefox\Profiles\&lt;profile&gt;\
    The "Application Data" folder in XP/Win2K and the "AppData" folder in Vista/Windows 7 are hidden folders.
    *http://kb.mozillazine.org/Show_hidden_files_and_folders

  • Having problems with some links not working. Especially with webhost

    I sent this about 1/2 hour ago but never received the confirming email so thought I would try again. Sorry about the dupe if you did receive this.
    I am having a problem with Firefox. I have a website that I need to check stats with. I was able to login but when I clicked on the link for the stats nothing happened. No new page, no new window, no new screen. I tried all links and still nothing. At bottom of page it said "done". Then I got out of the webhost and tried other links, some worked some didn't.
    I went into Safari to check, and I was able to get my stats, so I tried again on Firefox, still nothing. I noticed a few other problems also, where I got the strangest things happening. Like when I tried to get on GoogleAds and YahooAds it didn't recognize me and also started redirecting me to other stuff.
    I prefer using Firefox, is there anyway to make the fixes?

    Downgrading is not supported by Apple.
    For better or worse, the burden is on app developers to make their apps compliant to the current iOS. If they haven't done that, then unfortunately users are stuck until they do so. The most you can do is communicate your issues to your app developers and see if they will get an update out to make their app work again. That or find another app.

  • Trouble with while loop, not sure what to put in it in my project

    I'm making a class to a simple command line craps game. I must use a while loop to implement craps rules. The rules that i was given are:
    if your first roll is a 4, 5, 6, 8, 9, or 10, you roll again until either you get a 7 (you lose) or you get the number from your first roll. (i thought 7 or 11 wins, like in the next example)
    yeah, thats right, not very good directions. The first directions i had for a different way of doing it using if and else statements were:
    The player rolls the two dice.
    If the sum of the resulting die values is 7 or 11, the player wins.
    If the sum is 2, 3, or 12, the player loses.
    If something else is rolled, the player has to roll again to determine the outcome.
    If the sum of the second roll is the same as what the player rolled the first time, the player wins. Otherwise the player loses.
    (You might get a pair of dice and play a few rounds to try it.)
    here's my code that i have so far for my craps class, in the middle section, i have previous code that i used for if else statements, that is what im trying to replace: package games;public class Craps {
    private Dice dice1;
    private Dice dice2;
    private int gamesPlayed;
    private int gamesWon;
    private boolean lastGameWon;
    private boolean gameOver;
    private int firstRoll;
    private int secondRoll;
    public Craps() {
    dice1 = new Dice(6);
    dice2 = new Dice(6);
    gamesPlayed = 0;
    gamesWon = 0;
    lastGameWon = false;
    firstRoll = 1;
    secondRoll = 2;
         //returns firstroll
    public int getFirstRoll(){
    return firstRoll;
         //returns secondroll
    public int getSecondRoll(){
    return secondRoll;
    public int getGamesPlayed(){
    return gamesPlayed;
    public int getGamesWon(){
    return gamesWon;
    public boolean lastGameWon(){
    return lastGameWon;
         public int nextSum()
         dice1.roll();
         dice2.roll();
         return dice1.getSideUp() + dice2.getSideUp();
    public void play()
              firstRoll = nextSum();
    if (firstRoll == 7 || firstRoll == 11)
              gameOver = true;
              gamesWon++;
              if (firstRoll == 2 || firstRoll == 3 || firstRoll == 12)
              gameOver = true;
                   else{
                   gameOver = false;
              while (gameOver == false)
              secondRoll++;
    public String toString()
    return "games - " + gamesPlayed + ", won - " + gamesWon + ", last game won - " + lastGameWon + " First Roll - " + firstRoll +
    ", Second Roll - " + secondRoll;
    i'm really confused on how to get the while loop will keep starting the game over if it is false, am i using the right approach? Also i have to use a while loop, its for a school project.
    thanks.

    The code you asked for could be:
    package games;
    public class Craps {
        private Dice dice1;
        private Dice dice2;
        private int gamesPlayed;
        private int gamesWon;
        private boolean lastGameWon;
        private boolean gameOver;
        private int firstRoll;
        private int secondRoll;
        public Craps()
            dice1 = new Dice(6);
            dice2 = new Dice(6);
            gamesPlayed = 0;
            gamesWon = 0;
            lastGameWon = false;
            firstRoll = 1;
            secondRoll = 2;
         //returns firstroll
        public int getFirstRoll(){
            return firstRoll;
         //returns secondroll
        public int getSecondRoll(){
            return secondRoll;
        public int getGamesPlayed(){
            return gamesPlayed;
        public int getGamesWon(){
            return gamesWon;
        public boolean lastGameWon(){
            return lastGameWon;
        public int nextSum()
            dice1.roll();
            dice2.roll();
            return dice1.getSideUp() + dice2.getSideUp();
        public void play() {
            gamesPlayed++;
            firstRoll = nextSum();
            if (firstRoll == 7 || firstRoll == 11)
                gamesWon++;
                lastGameWon = true;
            else if (firstRoll == 2 || firstRoll == 3 || firstRoll == 12)
                lastGameWon = false;
            else
               secondRoll = nextSum();
               if (firstRoll == secondRoll)
                  gamesWon++;
                  lastGameWon = true;
               else
                  lastGameWon = false;
        public String toString()
            return "games - " + gamesPlayed + ", won - " + gamesWon + ", last game won - " + lastGameWon + " First Roll - " + firstRoll +
                    ", Second Roll - " + secondRoll;
    }I'm not sure of craps rules, the code above makes a first roll and if game isn't won or lose at once (7 and 11 wins, 2,3 or 12 lose) a second roll is done. If the second roll is equals to the first made then the game is won else the game is lose. Is it right?

  • I am having problem with my phne not being able to pick up any wi - fi service ?

    Does anyone have a similar problem with their Motorola phone ?

    Do you mean after a phone update? Do you mean just at home? Does it happen everywhere?  Do you have wifi turned on? If its on and your not connecting just clear out the connections (forget) then reset up the connections and see if that helps.  Did you get a Jelly Bean update? Many people have had wifi connections issues because your router is either outdated and not supported with the new os, or it needs a firmware update.  Post back with more information.

  • Is anyone having problems with FB app not opening and calendar appts disappearing after update

    Since I did the most recent update yesterday, the FBI app won't open.  Also, all my reminders have disappeared.  All still work on iPhone, just not on pad.
    Thanks in advance!

    My problems with the Healt App are all over the map. The information on Withings Health Mate is totally accurate, and updates immediately.  I have their scale (since 2011) and wireless blood pressure monitor. Also, I find the heart rate senson on the iPhone 6 to work well, every time.
    This issue for me is with Apple's Health app. I get ridiculous readings on the Dashboards. For example, it shows my daily average in steps as 170,688, and miles walked at 80. Hardly! Additionally, the Dashbord widgets will disappear/reappear for no reason. I have tried switching the priority of data sources for the steps dashboard between Withings and my iPhone 6 (because it is indicated that the top source governs the dashboard info), to no avail.
    Lastly, I don't know how to interpret the infomration on the individual dashboards. On the same line as the word "Steps" there is a number, i.e. 14,272 steps, and just under it the word "Today." However, when I switch from "Day," "Week,," "Month," and "Year," those number don't change. Below the word Today is a number (which changes all the time), and at the bottom of the widget, just above the month (October now) is the number 1,149,749. Nice.
    I would like to get the Apple Watch next year, but if the Health App cannot be fixed I may not.

  • I was messing with the computer, not sure what i hit but now all my toolbars at the top of the screen are gone? (file, edit, history, tools and my forward and back button). Please help me get these settings back to the way they were?

    My file, edit, view, history, bookmarks, tools, and help buttons at the top of the screen are gone, along with my forward and back button.

    For details of how to restore it, see https://support.mozilla.com/kb/menu+bar+is+missing
    Once the menu bar is restored, you can use the Toolbars entry in the View menu to restore other toolbars such as the navigation toolbar.

Maybe you are looking for

  • Field value is not getting populated in Display mode

    Hello All, I have created a custom drop down field in the DEAL component through EEWB. From the GUI, I could able to select a value form the drop down list field and save it. In DISPLAY mode,  the value is not showing but when I change the screen to

  • Wireless printing from a Deskjet F380 All In One printer

    Is it possible to print from my G72 laptop to my F380 AIO printer without using a cable. I understand a wireless mouse and laptop operate by plugging a device into a desktop's USB port. Is something similar possible by plugging a device into teh prin

  • My flash wont automatically play when i go to the website???

    My flash animation wont automatically play when i go to the website. It will only play if i right click on the flash image and click play. Am i missing something in my flash document? Any suggestions? thanks,

  • Method to Generate Report...??

    Hello, i want to know is that any method that can generate bar chart with jsp, mysql, tomcat?? I tried to search from internet, and i found out SwissChart is one of the method to generate graph... but i tried to follow the step of installation n the

  • Solaris 11.1 Comstar FC target

    Hello, I have a problem with the comstar as a FC target. New install of Solaris 11.1 HBA is an Emulex LPe11002 Brocade 5100B switches 2x 10x 3TB NL-SAS disks in raidz2 in pool It all works, but the speed is unusable slow to the LUN. iSCSI work and I