aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes read a txt into a textarea Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "read a txt into a textarea" Watch "read a txt into a textarea" New topic
Author

read a txt into a textarea

Marcelo Bordolli
Ranch Hand

Joined: Sep 03, 2012
Posts: 46

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!!!


I know is only java
BUT I LIKE IT!!!
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18987
    
    8

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:


Marcelo Bordolli
Ranch Hand

Joined: Sep 03, 2012
Posts: 46

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();
};
}
Marcelo Bordolli
Ranch Hand

Joined: Sep 03, 2012
Posts: 46

Can you explain me better how is that ai can use the standar api for this trouble?

THANK YOU FOR THE ANSWERS!!!
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18987
    
    8

Marcelo Bordolli wrote:I made the changes but still nothing


Does that code run when you click on whatever it is?
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> jMenu2ActionPerformed

is jMenu2 a JMenu?
Kemal Sokolovic
Bartender

Joined: Jun 19, 2010
Posts: 825
    
    5

The code you posted has syntax errors. You should check them before going into functionality.


The quieter you are, the more you are able to hear.
Marcelo Bordolli
Ranch Hand

Joined: Sep 03, 2012
Posts: 46

i use netbeans and the code compiles fine it just dont do as supose
Kemal Sokolovic
Bartender

Joined: Jun 19, 2010
Posts: 825
    
    5

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?
Marcelo Bordolli
Ranch Hand

Joined: Sep 03, 2012
Posts: 46

i forgot to put them but i did declare all the variables. and no exception happend.
Kemal Sokolovic
Bartender

Joined: Jun 19, 2010
Posts: 825
    
    5

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.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
you should have taken the hint from my question.
the solution is in that hint
Marcelo Bordolli
Ranch Hand

Joined: Sep 03, 2012
Posts: 46

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
Kemal Sokolovic
Bartender

Joined: Jun 19, 2010
Posts: 825
    
    5

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.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18987
    
    8

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.)
Kemal Sokolovic
Bartender

Joined: Jun 19, 2010
Posts: 825
    
    5

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.
Marcelo Bordolli
Ranch Hand

Joined: Sep 03, 2012
Posts: 46

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!!
Marcelo Bordolli
Ranch Hand

Joined: Sep 03, 2012
Posts: 46

Thank you Michael , also missed his post!!
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18987
    
    8

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.
Kemal Sokolovic
Bartender

Joined: Jun 19, 2010
Posts: 825
    
    5

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: read a txt into a textarea