• Post Reply Bookmark Topic Watch Topic
  • New Topic

attaching file question  RSS feed

 
Kristol Crawley
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

If I already have a file somewhere that I just want to attach to an email, do I still have to read it in to write it out? When I tried doing it that way it gives me a null pointer when it's writing the data. When I check the file it's wiped all the data. I'm not sure what I'm doing wrong.

String pdf2Name = getPage2Dir();FileOutputStream pdfFile = new FileOutputStream(pdf2Name);
pdfFile.write(getStreamInfo().toByteArray());
pdfFile.close();
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Kristol Crawley:
do I still have to read it in to write it out?

Yes


When I tried doing it that way it gives me a null pointer when it's writing the data. When I check the file it's wiped all the data.

Sounds like you opened your "input" file for writing rather than reading. If pdfFile is the input file in your code above, this is exactly what you are doing.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!