Results 1 to 8 of 8
- 04-05-2011, 11:27 AM #1
Member
- Join Date
- Mar 2011
- Posts
- 30
- Rep Power
- 0
How to Write to a File Using a Method
Hi all,
I Need to write an Function in java which can take a parameter as filename and String Array and Write That Array to the given File. How to I Implement this using Function.
public void WriteToFile(String f, String []arr)
{
f1=new File(this.f);
f.createNewFile();
FileWriter fstream = new FileWriter(f,true);
BufferedWriter out = new BufferedWriter(fstream);
out.write([]arr+"");
out.close();
}
Please Help Me for doing this I am New to this
- 04-05-2011, 11:44 AM #2
Ever heard of a loop? They come in 4 flavors: for, enhanced-for, while and do-while. You'll need to use one of them.
db
- 04-05-2011, 12:04 PM #3
Member
- Join Date
- Mar 2011
- Posts
- 30
- Rep Power
- 0
Thanks Mr.Darryl.Burke,
Can you tell me following method is right or wrong????????
waiting for positive reply....
- 04-05-2011, 12:26 PM #4
- 04-05-2011, 12:30 PM #5
Member
- Join Date
- Mar 2011
- Posts
- 30
- Rep Power
- 0
public void WriteToFile(String f, String []arr)
{
f1=new File(this.f);
f.createNewFile();
FileWriter fstream = new FileWriter(f,true);
BufferedWriter out = new BufferedWriter(fstream);
out.write([]arr+"");
out.close();
}
- 04-05-2011, 01:49 PM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Does that even compile?
- 04-06-2011, 04:10 AM #7
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
You didn't take darryls advice, he suggested a loop. We dont give you the code, instead we help you figure it out. Here is some pseudocode.
Java Code:open streams loop write to file end loop finally close stream end finally
- 04-06-2011, 06:50 AM #8
Similar Threads
-
Writing a method to write a method?
By balla in forum New To JavaReplies: 5Last Post: 04-01-2011, 12:05 PM -
Write a program that sorts data from a text file and sort them in a file
By danmgz45 in forum New To JavaReplies: 6Last Post: 12-01-2010, 05:31 AM -
Question about the write method in DataOutput
By shai in forum New To JavaReplies: 2Last Post: 07-31-2010, 06:49 AM -
how to write method syntax ?
By Bader in forum New To JavaReplies: 2Last Post: 03-14-2010, 05:58 PM -
Trying to write toString method
By curious in forum New To JavaReplies: 3Last Post: 10-28-2009, 02:43 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks