How to upload a file in thread without interrupting other work?
<p>i am uploading a file in thread by writting this code</p>

<pre><code>import java.io.*;
public class FileUploadThread extends Thread {

    File f1, f2;
    String fileName;
    InputStream stream;
    byte[] b = new byte[1024];

    public FileUploadThread(File f1, File f2, InputStream stream, String filename) {
        System.out.println("external class file name---&gt;" + filename);
        this.f1 = f1;
        this.f2 = f2;
        this.stream = stream;
        this.fileName = filename;
    }

    public void run() {
        try {
            f2 = new File(f1, fileName);
            OutputStream w = new FileOutputStream(f2);

            int res = stream.read(b);
            System.out.println("res = "+res);
            while (res &gt;= 0) {
                for (int i = 0; i &lt; res; i++) {
                    w.write(b);
                }
              res = stream.read(b);
              System.out.println("res---&gt;" + res);
            }

        } catch (Exception e) {
            System.out.println("In the run method of the thread");
            e.printStackTrace();
        }
    }

}
</code></pre>

<p>It shows me <code>ArrayIndexOutOfBoundsException</code>.</p>
