Code Comments
Programming Forum and web based access to our favorite programming groups.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
Post Follow-up to this messageRow 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 haveyou 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
Post Follow-up to this messagewhy 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
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.