• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

About Menu Items

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I created my own notepad...
How can I open a text file and append all the texts in my text area?
How can I save what I've written in my text area?
Please help me. Thanks!
 
Ranch Hand
Posts: 1374
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Cedric ,

I think to get some replies you should post your question at Swing / AWT / SWT / JFace forum.
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd suggest the I/O forum instead, since the reading of the file is harder than adding it to a JTextArea.
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"eLL Pascual"?? Is that a real name?

And this thread has nothing to do with menu items. Please make sure your subject line bears some resemblance to the contents of your thread.

With the development of the Formatter class in Java 5 it became very easy to write to a text file. You just pass the File to the constructor of the Formatter object and tell it to format. Similarly reading a File is really easy with the Scanner class.

If Formatter and Scanner are all you need, then I think I shall keep the thread here, otherwise I can move it to IO later.
 
Vikas Kapoor
Ranch Hand
Posts: 1374
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yeah campee! It's his real name. Initially he used 'Cedric Diggory' (Harry Potter) as a Name. So i was just kidding.Go easy.
 
Rob Spoor
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I already had contact with him about it, and it's his real name, albeit abbreviated. Kind of like how William can become Bill.
 
Campbell Ritchie
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Rob. I stand corrected.

Ell: How are you getting on with it? Have you got it to work with Scanner or Formatter? Should I move this thread elsewhere?
 
eLL Pascual
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My real name is rafael. It became eLL because my friends wanted a one syllable nick so they decided to change it to eLL (rafa[EL]).

To Campbell Ritchie:
I am already done with scanner but I have some problems with it. the other one(formatter), I dont know that yet.

To all:
I have more questions because there has been some progress in my work. So please go to my other posts. Thanks
 
eLL Pascual
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I thought I can move my post myself but this is what I got.

"Only administrators or moderators may perform this action."

Campbell Ritchie, please move my post to I/O forum.
 
eLL Pascual
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
About the title of my post...

Actually, I created open and save menu items so I thought "About menu items" is the best title for my post. But my question is how to make them work.
 
Campbell Ritchie
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you, eLL. You are right; I can move this thread and you can't.

Please post more details of what you are doing with Scanner; it will give a better idea of what is going wrong.
Formatter is more-or-less the opposite of Scanner; you can use it to write to a text file, and also set formats with % tags while you are doing it.

Sorry for messing you around about your displayed name, and sorry even more for what follows


I-O I-O away this thread will go!
 
Rob Spoor
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rafael,

Please use the edit button instead of posting several posts after each other in the future.
[ June 05, 2008: Message edited by: Rob Prime ]
 
eLL Pascual
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Details? Ahhmmm. Actually I decided to stop using Scanner because I saw a demo using FileInputStream and FileOutputStream working very well. I just followed how the programmer used the codes and found myself dealing with the same problem I had when I was still using Scanner. FileInputStream is reading only one line of the text area, it is ignoring the succeeding lines. While the FileOutputStream in the demo is writing texts in a text file the way I typed the texts in the textArea. But in my own program, it is writing the texts in one straight line only even though I had several lines. Look at my example.

In my textArea:

Cedric
Diggory
Harry Potter

In the text file:

[] - supposedly a square

Cedric[]Diggory[]Harry Potter

But the demo is working well. I dont know what is the problem. Actually the only difference between my codes and the programmer's code are names.

Since Campbell told me that Scanner is very easy to use, I guess I will show you my code and tell me what is wrong. The problems with my Scanner is the same with the problems I mentioned above.

code:
----------------------------------------------------------------------------

else if(source.getText().equalsIgnoreCase("open")){
System.out.print("Open Press");
int returnVal = fileChooser.showOpenDialog(notepad.this);
File file = fileChooser.getSelectedFile();

Scanner s = null;
try {
s = new Scanner(new BufferedReader(new FileReader(file)));

while (s.hasNext()) {
textArea.append(s.next());
}
}
catch(Exception e){}
finally {
if (s != null) {
s.close();
}
}

}

----------------------------------------------------------------------------

I dont know how to use Formatter yet but I already downloaded a Formatter API so I guess I have to study it first.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic