Be a Supporter!

java PrintWriter without delete

  • 756 Views
  • 2 Replies
New Topic Respond to this Topic
ronk
ronk
  • Member since: Dec. 23, 2007
  • Offline.
Forum Stats
Member
Level 13
Programmer
java PrintWriter without delete 2012-03-24 22:54:15 Reply

I'm trying to write a program in java and i was wondering if there was anyway to print to a file without wiping the file first.
I'm currently trying to use a PrintWriter but i that doesn't work. is there another/better way?

I'm new to programming btw, so i don't know a lot of java's shenanigans.

Redshift
Redshift
  • Member since: Feb. 12, 2005
  • Offline.
Forum Stats
Member
Level 15
Programmer
Response to java PrintWriter without delete 2012-03-24 23:30:43 Reply

At 3/24/12 10:54 PM, ronk wrote: I'm trying to write a program in java and i was wondering if there was anyway to print to a file without wiping the file first.
I'm currently trying to use a PrintWriter but i that doesn't work. is there another/better way?

I'm new to programming btw, so i don't know a lot of java's shenanigans.

Create a FileWriter stream with append mode set, then pass that into a new PrintStream instance. eg:

FileWriter fw = new FileWriter("<path>", true);
PrintStream ps = new PrintStream(fw);
ps.println("Hello, world!");

#include <stdio.h>
char*p="#include <stdio.h>%cchar*p=%c%s%c;%cmain() {printf(p,10,34,p,34,10);}";
main() {printf(p,10,34,p,34,10);}

BBS Signature
Redshift
Redshift
  • Member since: Feb. 12, 2005
  • Offline.
Forum Stats
Member
Level 15
Programmer
Response to java PrintWriter without delete 2012-03-24 23:34:42 Reply

Well, forgot that you specified PrintWriter, in which case you should be able to sub that directly into that example code instead.


#include <stdio.h>
char*p="#include <stdio.h>%cchar*p=%c%s%c;%cmain() {printf(p,10,34,p,34,10);}";
main() {printf(p,10,34,p,34,10);}

BBS Signature