title: Create text file dynamically in a specified directory, write data,read data from that file in java
body: <p>Recently i have tried to write code of above given title and the problem is that i could not get sufficient date to write upon have a look at my code .it is showing some errors like   </p>
  
  <p>it is showing invalid token for semicolon after tagfile.createnewfile();
   let us look at code:    </p>
  
  <p>public class WriteToFileExample {</p>
  
  <pre><code>String path = "G:"+File.separator+"Software"+File.separator+"Files";
  
   String fname= path+File.separator+"fileName.txt";
  
  boolean bool=false;
  
      File f = new File(path);
  
      File f1 = new File(fname);
  
      try {
  
          f1.createNewFile();
  
          bool=f.mkdirs() ;
  
      } catch (IOException e) {
  
          // TODO Auto-generated catch block
  
          e.printStackTrace();
      }
  }
  private static final String FILENAME = "G:\\Software\\Files\\anil.txt";
  
  static Scanner sc = new Scanner(System.in);
  
  public static void main(String[] args) {
  
      String content = null;
  
      String[] str = new String[100];
  
      try (BufferedWriter bw = new BufferedWriter(new FileWriter(FILENAME))) {
  
          System.out.println(" enter no.of line to be inserted into file");
  
          int k = sc.nextInt();
  
          for (int i = 0; i &lt;= k; i++) {
  
              System.out.println(" enter " + i + " line data");
  
              content = sc.nextLine();
  
              bw.write(content);
  
              str[i] = content;
  
          }
  
          System.out.println("The content present in\n 
  </code></pre>
  
  <p>G:\Software\Files\anil.txt is:");</p>
  
  <pre><code>        for (int i = 1; i &lt;= k; i++)
              System.out.println(str[i]);
  
      } catch (IOException e) {
  
          e.printStackTrace();
  
      }
  
  }
  </code></pre>
  
  <p>}</p>