title: Program to Copy a Text File to another Location using Keyboard input
body: <p>I am writing a program to copy a text file to another file location from keyboard input and am having trouble. The file names are in the correct places when entered from the keyboard, but the content is not there. I have gotten one line to copy correctly into the next file.  At the moment, I am receiving a cannot find symbol error on line 41.</p>
  
  <pre><code>    import java.io.*;
      import java.util.*;
  
      public class lity
      {
       public static void main(String[] args)
       {
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Directory of file to be copied");
        String dir = keyboard.nextLine();
        System.out.println("Name of file to be copied");
        String file = keyboard.nextLine();
        File copied = new File(dir, file);
  
        BufferedReader in =new BufferedReader(new FileReader(copied));
        String str;
  
        while((str = in.readLine())!=null)
        {
         char[] n;
         n = str.toCharArray();
        }
        in.close();
  
  
  
        System.out.println("Path of pasted file");
        String pdir = keyboard.nextLine();
        File newdir = new File(pdir);  
  
        if(!newdir.exists())
        {
         newdir.mkdir();
        }
  
        System.out.println("pasted file name");
        String pfile = keyboard.nextLine();
        File myfile = new File(newdir, pfile);
  
        FileWriter stream = new FileWriter(myfile);
  
        stream.write(n);
        stream.close();
        }
  
       }
  </code></pre>
  
  <p>new code</p>
  
  <pre><code>    import java.io.*;
      import java.util.*;
  
      public class CopyFile
      {
       public static void main(String[] args)
       {
        String s = " ";
        StringBuilder sb = new StringBuilder(s);
  
  
        Scanner keyboard = new Scanner(System.in);
        System.out.println("enter directory path of the file to be pasted:");
        String dirName = keyboard.next();
        System.out.println("enter file name of the file to be copied");
        String fileName = keyboard.next();
        try
        {
         File input = new File(dirName, fileName);
  
  
  
         Scanner ind = new Scanner(input);  
         BufferedReader in = new BufferedReader(new FileReader(input));
         String str;
  
         try
         {
          while(ind.hasNextLine())
          {
           str = in.readLine(); 
           sb.append(str+"\n");
          }
          in.close();
          ind.close();
         }
  
         catch(IOException e)
         {
          System.out.println("IOException");
         }
  
         System.out.println("path of file to be pasted");
         String dir = keyboard.next();
         File myDir = new File(dir);
  
         if(!myDir.exists())
         {
          myDir.mkdir();
         }   
  
  
         System.out.println("enter name of the file to be pasted");
         String mfile;
         mfile = keyboard.next();
         try
         {
          File myFile = new File(myDir, mfile);
  
          PrintWriter pw = new PrintWriter(new FileWriter(myFile));
  
          String nstr;
          nstr = sb.toString();
      char[] n = nstr.toCharArray();
          for(int d = 0;d &lt; n.length; d++)
      {
       pw.write(n[d]);
      }
          pw.close();
         }
        catch(IOException e)
        {
         System.out.println(e);
        }
       }
         catch(FileNotFoundException e)
         {
          System.out.println(e);
         }
        }
       }
  </code></pre>