Results 1 to 4 of 4
  1. #1
    Richman118 is offline Member
    Join Date
    Dec 2010
    Posts
    3
    Rep Power
    0

    Exclamation Writing data into a file Please Help!

    I am having a problem with one part of my program i have to "have a method named "public void generateEmployees(int howmany)". In this method, based
    # on the value of the input parameter "howmany", you create "howmany" employees and store them in # the variable "allE" and have a method named "public void storeInfo(String filename)" in which you write out all employee information into a file
    " So far I have:
    private final Employee[] allE()
    {
    return allE();
    }


    public void generateEmployees(int howmany)
    {
    Employee[] allE = new Employee[howmany];
    for(int i = 0; i<howmany; i++)
    {
    allE[i] = new Employee(Generator.generateName(5), Generator.generateName(4), Generator.generateSSN(), Generator.generateID(6));
    allE[i].print();
    }
    }

    public void storeInfo(String filename)throws IOException
    {
    File file = new File(filename);
    if (!file.exists())
    {
    System.out.println("File does not exist");
    System.exit(1);
    }

    PrintWriter pw = new PrintWriter(filename);
    for(int i = 0; i<allE().length; i++)
    {
    Employee [] a = allE();
    pw.print(a);
    //*** i think that i am missing a part here!

    }
    pw.close();
    }

    I am sorry i do not know much about java any help at all would be greatly appreciated! thank you so much to all who respond!!!
    Last edited by Richman118; 12-16-2010 at 11:02 PM.

  2. #2
    Richman118 is offline Member
    Join Date
    Dec 2010
    Posts
    3
    Rep Power
    0

    Exclamation Sorry I have to:

    I am having a problem with this part:

    You have a method named "public void storeInfo(String filename)" in which you write out all employee information into a file

  3. #3
    Richman118 is offline Member
    Join Date
    Dec 2010
    Posts
    3
    Rep Power
    0

    Default one error fixed

    I found the problem in my program what i originally thought was the problem was not. I now believe that the problem lies in
    private Employee[] allE()
    {
    return allE();
    }
    and in the for loop in my storeInfo loop

    for(int i = 0; i<allE().length; i++)
    {
    Employee [] a = new Employee[allE().length];
    a[i] = new Employee(Generator.generateName(5), Generator.generateName(4), Generator.generateSSN(), Generator.generateID(6));
    pw.println(a[i].getfirstName()+"|"+a[i].getlastName()+"|"+a[i].getid()+"|"+a[i].getssn());

    when i am using allE().length for my ranges in these loops i am getting a StackoverFlowError.

    Any ideas anyone?
    Thanks again!!:confused:
    }

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Again, when posting code here, please use code tags so that your code will retain its formatting and thus will be readable -- after all, your goal is to get as many people to read your post and understand your code as possible, right?

    To do this, highlight your pasted code (please be sure that it is already formatted when you paste it into the forum; the code tags don't magically format unformatted code) and then press the code button, and your code will have tags.

    Another way to do this is to manually place the tags into your code by placing the tag [cod&#101;] above your pasted code and the tag [/cod&#101;] below your pasted code like so:

    Java Code:
    [cod&#101;]
      // your code goes here
      // notice how the top and bottom tags are different
    [/cod&#101;]
    There's no need to repost your code, just simply edit your posts above and add the tags.

Similar Threads

  1. Writing the data into RandomAccessFile
    By vasavi.singh in forum New To Java
    Replies: 5
    Last Post: 01-31-2013, 07:12 AM
  2. Replies: 2
    Last Post: 05-01-2010, 09:16 PM
  3. problem with writing new data into file
    By sara12345 in forum New To Java
    Replies: 2
    Last Post: 04-13-2010, 02:34 AM
  4. Replies: 1
    Last Post: 02-27-2010, 01:29 AM
  5. Writing Data or Objects?
    By Goodwine in forum New To Java
    Replies: 2
    Last Post: 11-26-2008, 12:36 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •