Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Editing a text file  RSS feed

 
Wes Beere
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have created a text file, which I can read and write to, but I want to know if there is an easy way to delete text (one line at a time) from a GUI, without the user editing it directly themselves(i.e. selecting the text somehow(Haven't figured this out either) then click a button, and it magically disappears in the file). Currently I have the text displayed in a JTextArea which is in a JScrollPanel.
 
Wes Beere
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
While awaiting a reply, I finally figured out how to select text, and identify it, but I still need to find out how to edit the file, preferably without rewriting the whole thing every time.
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Wes Beere:
I still need to find out how to edit the file, preferably without rewriting the whole thing every time.
That's essentially your only option. Technically, you only have to rewrite the file starting from the point where the text was deleted. This is why most applications save to disk only when the user tells them to.
 
Wes Beere
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, I think I've figured out an easy way to do that now too, using lists to hold each line while they are being edited, then write the list when the user is done.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!