Forums Register Login

read a txt into a textarea

+Pie Number of slices to send: Send
i got a desktop program that has a menu bar and a textArea, wen i presS the button on the menubar the folowing actionperformed happend:



WHAT I WANT IS TO OPEN MY TXT FILE BY PRESSING THE MENU BAR BUTTON AND READ IT AND PUT THE READING ON THE TEXTAREA IN THE APLICATION, BUT THAT HASNT BEEN THE RESULT, I WANNA KNOW WERE IS THE ISSUE
THANKS RANCHERSS!!!
+Pie Number of slices to send: Send
There's a good chance that some kind of exception is being thrown. However you will never know, because your code ignores exceptions. Try this instead:



However, having said that I suspect your problem is that your file path is nothing like an actual Windows file path. Where did all those colons (:::) come from?

And finally you don't need to write the code yourself to read from the file and write it into the text area. You can just use a method from the standard API:


+Pie Number of slices to send: Send
I made the changes but still nothing

private void jMenu2ActionPerformed(java.awt.event.ActionEvent evt) {
try{
FileReader Fichero=new FileReader("C:\\Documents and Settings\\Chelo\\Mis documentos\\NetBeansProjects\\Obliga\\src\\presentacion\\Grupo.txt");
BufferedReader leer=new BufferedReader(Fichero);
while((Text=leer.readLine())!=null){
jTextArea1.append(Text+ "\n"); //append Concatena la linea leida
}
leer.close();


}catch(IOException e){
e.printStackTrace();
};
}
+Pie Number of slices to send: Send
Can you explain me better how is that ai can use the standar api for this trouble?

THANK YOU FOR THE ANSWERS!!!
+Pie Number of slices to send: Send
 

Marcelo Bordolli wrote:I made the changes but still nothing



Does that code run when you click on whatever it is?
+Pie Number of slices to send: Send
> jMenu2ActionPerformed

is jMenu2 a JMenu?
+Pie Number of slices to send: Send
The code you posted has syntax errors. You should check them before going into functionality.
+Pie Number of slices to send: Send
i use netbeans and the code compiles fine it just dont do as supose
+Pie Number of slices to send: Send
It can't compile fine, since you use variable that you didn't declare.
Do you get any exception? If so, can you copy the message you get?
+Pie Number of slices to send: Send
i forgot to put them but i did declare all the variables. and no exception happend.
+Pie Number of slices to send: Send
Than it probably means the file you are reading is empty.

EDIT: It is a good practice to use Lower Camel Case for naming your variables. Or at least stick to just one naming convention.
1
+Pie Number of slices to send: Send
you should have taken the hint from my question.
the solution is in that hint
+Pie Number of slices to send: Send
the file contains the following:


Alfredo Garcia 34353454
Richard Blemen 23525342
Mick Jagger 24523523
Robert Pattinson 65434518
Hayden Pannetiere 36486712
Alice Eve 97246590
Hugo Beaven 28288282
Beavis Acdc 54545445
Buthead Acdc 12121221
Mathias Oviedo 78787887
Marcos Viera 29292992
Wesker Almond 33333333
Trinity Gogo 22222222
Tia Carrera 44444444
Kristen Stweart 66666666
Charlize Theron 77777777
Denzel Washington 99999999
Angus Young 23312323
Malcom Young 23311332
Jhon Lennon 57575775
Jason Statam 83838383
Mario Bros 91291291
Luigi Bros 48297538
Amy Adams 98239832
Isla Fisher 20202020

and you are right whit the naming conventions i should stick whit one
+Pie Number of slices to send: Send
 

Michael Dunn wrote:you should have taken the hint from my question.
the solution is in that hint


Missed that one, thought the listener is for JMenuItem. That's the problem, Marcelo Bordolli.
+Pie Number of slices to send: Send
 

Kemal Sokolovic wrote:Than it probably means the file you are reading is empty.



We don't even know if that code is being executed. (I asked but received no answer.)
+Pie Number of slices to send: Send
 

Paul Clapham wrote:

Kemal Sokolovic wrote:Than it probably means the file you are reading is empty.



We don't even know if that code is being executed. (I asked but received no answer.)



I always suppose people run it through debugger to at least make sure execution comes to the code they are asking for, before posting a question like this. Guess that's not the case.
+Pie Number of slices to send: Send
FIXED!!! THE ISSUE WAS SO DUMB
I was pleacing the code in the wrong place, i change it to jmenuitem and it works perfectly fine

Thank you all , Paul
Kemal and the rest!!!

I have millions of code here so i guess in one point all start to look a like, Thank you all!!
+Pie Number of slices to send: Send
Thank you Michael , also missed his post!!
+Pie Number of slices to send: Send
 

Kemal Sokolovic wrote:I always suppose people run it through debugger to at least make sure execution comes to the code they are asking for, before posting a question like this. Guess that's not the case.



You might think so, but quite often beginners produce this sort of thing on the first day after they install Netbeans, and they have no idea how to use Netbeans for debugging. Or even what debugging is, for that matter.
+Pie Number of slices to send: Send
 

Paul Clapham wrote:You might think so, but quite often beginners produce this sort of thing on the first day after they install Netbeans, and they have no idea how to use Netbeans for debugging. Or even what debugging is, for that matter.


Apparently that is the case, I'll keep that in mind.
You have to be odd to be #1 - Seuss. An odd little ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 7391 times.
Similar Threads
Problem with writing in txt file
Comparing two huge files
File reading
adding a save method
Writing data into file from a String variable
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 20:29:38.