Results 1 to 4 of 4
- 12-16-2010, 10:58 PM #1
Member
- Join Date
- Dec 2010
- Posts
- 3
- Rep Power
- 0
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.
- 12-16-2010, 11:01 PM #2
Member
- Join Date
- Dec 2010
- Posts
- 3
- Rep Power
- 0
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
- 12-17-2010, 02:19 AM #3
Member
- Join Date
- Dec 2010
- Posts
- 3
- Rep Power
- 0
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:
}
-
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 [code] above your pasted code and the tag [/code] below your pasted code like so:
There's no need to repost your code, just simply edit your posts above and add the tags.Java Code:[code] // your code goes here // notice how the top and bottom tags are different [/code]
Similar Threads
-
Writing the data into RandomAccessFile
By vasavi.singh in forum New To JavaReplies: 5Last Post: 01-31-2013, 07:12 AM -
Selecting Specific Data in a file and writing to another
By macpilz in forum New To JavaReplies: 2Last Post: 05-01-2010, 09:16 PM -
problem with writing new data into file
By sara12345 in forum New To JavaReplies: 2Last Post: 04-13-2010, 02:34 AM -
Im writing to a file and i want to skip lines while writing to a text file.
By Broden_McDonald in forum New To JavaReplies: 1Last Post: 02-27-2010, 01:29 AM -
Writing Data or Objects?
By Goodwine in forum New To JavaReplies: 2Last Post: 11-26-2008, 12:36 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks