[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: streams



Here's some generic code to write to a text file, maybe it will help.  If not, you can read up on the OutputStream classes I'm using and probably find out how to do what you want.

  OutputStream rawFile = null;
  OutputStream bufferedFile = null;
  PrintStream theFile = null;
 
  String data = "Whatever you want;
 
  // write it out to the logfile in buffered fashion.
  // average data size is 3K, so a 4K buffer ought to do
  //  for ensuring only a single disk write
  try {
   rawFile = new FileOutputStream("C:\whatever.txt", true);
   bufferedFile = new BufferedOutputStream(rawFile, 4096);
   theFile = new PrintStream(bufferedFile, true);
   theFile.println(data);
  }
  finally {
   if(theFile != null)
    theFile.close();
   if(bufferedFile != null)
    bufferedFile.close();
   if(rawFile != null)
    rawFile.close();
  }
 
Jeff
 
----- Original Message -----
Sent: Friday, October 11, 2002 3:30 PM
Subject: streams

Hi All,
 
I am reading data from an input stream and I want to write it to a file.  How do I do this?
 
Thanks,
Bill