title: Executing a net use command
body: <p>I need to execute a net use command which is written in a batch file to enable a drive. Batch file is as follows:</p>
  
  <pre class="lang-bat prettyprint-override"><code>net use * /delete /Y
  net use l: \\&lt;windows drive name&gt; /user:&lt;domain&gt;\&lt;username&gt; &lt;password&gt;
  </code></pre>
  
  <p>The above batch file enables a drive for me and its visible as L: drive to me.
  I need to execute this batch file through java code and then write the some files onto this drive.</p>
  
  <p>I am using the below code to execute this batch file:</p>
  
  <pre><code>String[] array = { "cmd", "/C", "start", "C:/file.bat" };
  Runtime.getRuntime().exec(array);
  </code></pre>
  
  <p>Problem is when I try to access the drive to write the files it gives me a path not found exception. Sometimes it runs and sometimes it doesn't.</p>
  
  <p>Friends can anyone help me to understand where is the issue. What wrong step I am performing. In case I am not clear with my question do let me know.</p>