Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

File output help
Hi,

I am having trouble writting from a JTextArea to a flat text file (locally)

I have tried using string tokenizer to tokenize the string first but with no
 luck,
Im stuck on the one :(

im a newbie so please take this into acount.
my snippet is below

//Post New Item from TextArea - To Vector, - then to Text File.
void postNewItem () {
try {
String Contents = singleTextArea.getText();
BufferedWriter output = new BufferedWriter( new FileWriter(urlTx) );
testVec.addElement(Contents);

Enumeration eNum = testVec.elements();
while (eNum.hasMoreElements()){
String pointer = (String)eNum.nextElement();
System.out.println("writen to file "+ pointer);
output.write(pointer);
output.close();

}//end while

Report this thread to moderator Post Follow-up to this message
Old Post
Row
04-21-04 02:34 PM


Re: File output help
Row wrote:
> I am having trouble writting from a JTextArea to a flat text file (locally
)
>

First, you need to define "having trouble".  Do you get an exception?
If so, what is it?  Do you get a compiler error?  If so, what is it?

A few comments on the code:

1. The output.close() is inside your while loop.  That means your file
will be opened once, but closed for each element of testVec.  Probably
not what you want.

2. The formatting is such that it's difficult to understand how your
code is organized.  It's conventional to indent the body of a block.
This may have  you and contributed toward your misplacing the
close() statement.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

Report this thread to moderator Post Follow-up to this message
Old Post
Chris Smith
04-21-04 04:51 PM


Re: File output help
why do u need a vector anyway?

Just get the text and write it to a file:

String contents = singleTextArea.getText();
BufferedWriter output = new BufferedWriter( new FileWriter(urlTx) );
output.write(contents);
output.close();

Fahd


soul_fly@punkass.com (Row) wrote in message news:<4d68ed39.0404210431.1470de18@posting.goog
le.com>...
> Hi,
>
> I am having trouble writting from a JTextArea to a flat text file (locally
)
>
> I have tried using string tokenizer to tokenize the string first but with 
no luck,
> Im stuck on the one :(
>
> im a newbie so please take this into acount.
> my snippet is below
>
> //Post New Item from TextArea - To Vector, - then to Text File.
> void postNewItem () {
>     try {
>    String Contents = singleTextArea.getText();
>    BufferedWriter output = new BufferedWriter( new FileWriter(urlTx) );
>    testVec.addElement(Contents);
>
>    Enumeration eNum = testVec.elements();
>    while (eNum.hasMoreElements()){
>    String pointer = (String)eNum.nextElement();
>    System.out.println("writen to file "+ pointer);
>    output.write(pointer);
>    output.close();
>
> }//end while

Report this thread to moderator Post Follow-up to this message
Old Post
Fahd Shariff
04-27-04 10:24 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Java Help archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:10 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.