Home > Archive > Java Help > April 2004 > File output help
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
|
| 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
| |
| Chris Smith 2004-04-21, 11:51 am |
| 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
| |
| Fahd Shariff 2004-04-27, 5:24 am |
| 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.google.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
|
|
|
|
|