File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes JFileChooser /text editor Help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "JFileChooser /text editor Help" Watch "JFileChooser /text editor Help" New topic

JFileChooser /text editor Help

Lord Byron Canica

Joined: Mar 29, 2004
Posts: 2
I am trying to open a txt file in a JTextArea. I know I have to use the .read() method, but how is executed so that the entire file can be viewed in my textArea? I am trying to create a simple text editor(like notepad) and I can't find any helpful tutorials to help me through this process.
Why does Java make it so hard for you to open and save/write to files. Seems like it should all come standard in a method instead of coding out the process every time?
Any good beginner tutorials for this would be appreciated too!!!
Nathaniel Stoddard
Ranch Hand

Joined: May 29, 2003
Posts: 1258
The text area will most likely need to be nested in a JScrollPane. As for reading and writing, Java makes one way to do it. Can you imagine the fun you'd have if you had to open/read/write files a different way for each context that you wanted to use it in? No, that wouldn't be much fun at all. One way. That's much easier. After about your third time, it only takes about 4 seconds anyways.
Oh, the Swing tutorial will probably be of help to you. It doesn't do much to unify all the components in a giant example that would bring everything together in your brain. But it does a good job, nonetheless.

Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
Luckily reading and writing to a file is pretty easy in Java. The I/O and Streams forum would be a good place to ask file I/O questions.
The Swing / JFC / AWT forum would be a good place to ask GUI questions, like working with JTextArea.
Now, you mentioned that you aren't finding any good tutorials. Here is a list of free on-line Java tutorials and books that I have found useful:
  • Sun's Java Tutorial
  • Introduction to Computer Science using Java by Bradley Kjell
  • Introduction to Programming Using Java by David J. Eck
  • Dick Baldwin's Java Programming Tutorials
  • Interactive Programming In Java by Lynn Andrea Stein
  • Bruce Eckel's Thinking In Java
  • JavaRanch's own Campfire Stories
  • Allen B. Downey's How To Think Like A Computer Scientist

  • Take a look at Sun's Java Tutorial, for sections on I/O and Swing.

    [How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
    I agree. Here's the link:
    subject: JFileChooser /text editor Help
    It's not a secret anymore!