- I am trying to upload multiple files via JSP to servlet.
- In servlet, trying to read the files one by one to get the file content and do some logic with the contents. when i try to read the file i am seeing below issue.
- Please note the issue is happening when i try to upload accessing the local host url in chrome/IE but code is working perfectly when i do the same within eclipse acessing the local host url
here is my code : String text =readstring(file) line causing issue with message FileNotFoundException .
if (ServletFileUpload.isMultipartContent(request)) {
    try {
        List < FileItem > multiparts = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request);
        System.out.println("get the multiparts" + multiparts.get(0));
        for (FileItem item: multiparts) {
            if (!item.isFormField()) {
                name = new File(item.getName()).getName();
                File file = new File(item.getName()); **
                String text = readstring(file); **
                //System.out.println("get the text"+text);
                message = GetAndPost(text);
                finaloutput = finaloutput + "************" + "\n" + name + " --->" + message + "\n" + "************";
                item.write(new File(UPLOAD_DIRECTORY + File.separator + name));
            }
            System.out.println("get the message" + name);
        }
        request.setAttribute("message", "File uploaded successfully.");
    } catch (Exception ex) {
        request.setAttribute("message", "File upload failed due to : " + ex);
    }
    FileUtils.writeStringToFile(new File("C:\\test\\test.txt"), finaloutput);
}
 
    