title: How do I use an inputStream as the text to an outputStream?
body: <p>I have two files, GettysburgAddress.txt, where the Gettysburg Address is written, and GettysburgAddressCopy.txt, which is an empty text file that I'm supposed to fill in with the Gettysburg Address, each sentence, till its period, on a different line.
  So I thought of this </p>
  
  <pre><code>import java.io.PrintWriter;`
  import java.io.FileNotFoundException;v`
  import java.util.Scanner;`
  import java.io.File;
  
  public class UltimateTextFileOutputDemo
  
  {
  
      public static void main(String[] args)
      {
          String writtenFileName = "C:\\Documents and Settings\\GettysburgAddressCopy.txt";
          PrintWriter outputStream = null;
          try
          {
              outputStream = new PrintWriter(writtenFileName);
          }
          catch (FileNotFoundException e)
          {
              System.out.println("Error opening the file" + writtenFileName);
              System.exit(0);
          }
  
  
          String readFileName = "C:\\Documents and Settings\\GettysburgAddress.txt";
          Scanner inputStream = null;
          try
          {
              inputStream = new Scanner(new File(readFileName));
          }
          catch (FileNotFoundException e)
          {
              System.out.println("Error opening the file " +
                              readFileName);
             System.exit(0);
          }
          while (inputStream.hasNextLine())
          {
              inputStream.useDelimiter(".");            // setting the period as the delimiter of the read piece of text, I'm sure it gets a single, complete sentence
              String line = inputStream.nextLine();
              outputStream.println(line);
          }
          outputStream.close();
          inputStream.close();
  
          System.out.println("The Gettysburg Address was written to " + writtenFileName);
  
      }
  }
  </code></pre>
  
  <p>When run, the program rightly creates the GettysburgAddressCopy.txt, if it doesn't exist yet, but it doesn't fill it with the speech. I realize the code naïvety is all in the three lines</p>
  
  <pre><code>inputStream.useDelimiter(".");
  String line = inputStream.nextLine();
  outputStream.println(line);
  </code></pre>
  
  <p>but then, what's the right code to write?
  Many thanks for giving me the best tips you can.</p>