• Post Reply Bookmark Topic Watch Topic
  • New Topic

How can i open a file in append mode  RSS feed

 
Greenhorn
Posts: 27
Notepad
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When ever i write some data on a file it will eraise the previous contents and write new contents on a file. How can i open a file in append mode without using any collection object like Vector and ArrayList
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
FileOutputStream and FileWriter both have constructors that take a boolean append argument.

Note, however, for non-text files, appending bytes to an existing files often results in a file that is not valid according the format we've been using to interpret that file.
 
Salman Mushtaq
Greenhorn
Posts: 27
Notepad
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear , i am new in programming field and not know these terms can you elaborate your answer.
 
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Something like a MS Word .doc file, or a .pdf file, has a specific layout. There are things in there that don't necessarily display, but change how the data is shown - tags that indicate "start printing in italics" or "stop indenting the text". There very well could be things on the end that indicate meta-data pieces, liked when the file was edited or by whom.

If you simply open a file and start putting stuff on the end, then when a program comes along to read it, you may have corrupted these values.

So, if you just have a file with plain text in it, there probably isn't a problem. If you have a .pdf, or .doc. or .xls, your new file will more than likely be garbage.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Salman Mushtaq wrote:Dear , i am new in programming field and not know these terms can you elaborate your answer.


Which terms?
 
Salman Mushtaq
Greenhorn
Posts: 27
Notepad
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes i got the point
FileOutputStream fs = new FileOutputStream("file.txt" , boolean true/false)

is am right ?
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!