Sending unlimited files from client to server
<p>So I have a homework from school wherein client must send unlimited files to the server. I made my idea like this.</p>

<ol>
<li>Client will send unlimited files to the server.</li>
<li>Server will redirect files uploaded by the client to my wamp server folder</li>
</ol>

<p>I have working code but this code can only send 1 file from client to server. I want also the file name of the uploaded files to increment because in my codes it only uses 1 file name, so if more clients uploaded their files they will overwrite the old file name.</p>

<p>For example: file01.rar next upload file02.rar and so on.</p>

<p>Here is my server code:</p>

<pre><code>public void run() {
    filePath = "C:/wamp/www/file.rar";
    byte[] aByte = new byte[1];
    int bytesRead;
    InputStream is = null;
    try {
        is = clientSocket.getInputStream();
    } catch (IOException ie) {
        ie.printStackTrace();
    }
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    if (is != null) {
        FileOutputStream fos = null;
        BufferedOutputStream bos = null;
        try {
            fos = new FileOutputStream(filePath);
            bos = new BufferedOutputStream(fos);
            bytesRead = is.read(aByte, 0, aByte.length);
            do {
                baos.write(aByte);
                bytesRead = is.read(aByte);
            } while (bytesRead != -1);
            bos.write(baos.toByteArray());
            bos.flush();
            bos.close();
        } catch (IOException ie) {
            ie.printStackTrace();
        }
    }
}
</code></pre>

<p>Here is my client code: </p>

<pre><code>BufferedOutputStream bos = null;
            try {
                bos = new BufferedOutputStream(s.getOutputStream());
            } catch (IOException ie) {
                ie.printStackTrace();
            }

            if (bos != null) {
                File uploadFile = new File(clientFacultyUploadTextField.getText());
                byte[] myFileSize = new byte[(int)uploadFile.length()];
                FileInputStream fis = null;
                try {
                    fis = new FileInputStream(uploadFile);
                } catch (FileNotFoundException fife) {
                    fife.printStackTrace();
                }
                BufferedInputStream bis = new BufferedInputStream(fis);
                try {
                    bis.read(myFileSize, 0, myFileSize.length);
                    bos.write(myFileSize, 0, myFileSize.length);
                    bos.flush();
                    bos.close();
                    clientFacultyUploadTextField.setText("Upload complete...");
                } catch (IOException ie) {
                    ie.printStackTrace();
                }
            }
</code></pre>
