I used the following code to upload.
It shows file uploaded but the files are stored in bytes.
What can i do now?
I am a beginner and I need a proper solution.
Code:
String user=request.getParameter("user");
String usertype=request.getParameter("user_type");
String contentType = request.getContentType();
String path=request.getParameter("file");
out.println("Content type is :: " +contentType);
if ((contentType != null))
{
DataInputStream in = new DataInputStream(request.getInputStream());
int formDataLength = request.getContentLength();
byte dataBytes[] = new byte[formDataLength];
out.print(dataBytes);
int byteRead = 0;
int totalBytesRead = 0;
while (totalBytesRead < formDataLength)
{
byteRead = in.read(dataBytes, totalBytesRead, formDataLength);
totalBytesRead += byteRead;
}
String file = new String(dataBytes);
int lastIndex = contentType.lastIndexOf("=");
String boundary = contentType.substring(lastIndex + 1,contentType.length());
int startPos =0;
int endPos =dataBytes.length;
String saveFile = "C:\\Users\\RABBY\\Documents\\NetBeansProjects\\testpage\\web\\"+user+"\\" +path;
FileOutputStream fileOut = new FileOutputStream(saveFile);
fileOut.write(dataBytes, startPos,endPos);
fileOut.flush();
fileOut.close();
out.println("File saved as " +saveFile);
}