I am trying to reading a CSV file and saving the in database. This part of the code is done. When I am reading the file from server it is working. But when I am trying to read the file from client machine it is not reading the file and throwing FileNotFoundException. This is how I have try this :-
try {
File file = new File(filePath);
if(file.exists()) {
System.out.println("File exists at the specified location");
}else {
System.out.println("Not able to find the file");
}
System.out.println("Successfully get the file");
URL serverURL = new URL(SERVER_URL);
System.out.println("Successfully get the URL");
HttpURLConnection serverCon = (HttpURLConnection) serverURL.openConnection();
System.out.println("Successfully opened the connection");
// setup connection
serverCon.setDoInput(true);
serverCon.setDoOutput(true);
serverCon.setUseCaches(false);
serverCon.setRequestProperty(FILENAME_HEADER, fileName); // send the filename through HTTP header
System.out.println("Successfully set the header");
// POST the file's bytes to the connections OutputStream
OutputStream toServer = serverCon.getOutputStream();
System.out.println("Successfully get the servlet output Stream");
FileInputStream fromFile = new FileInputStream(file);
System.out.println("Hopefully! this line will not print");//Here it is throwing exception
Can anyone help in acheiving this task. I have already tried it using MultipartRequest but later I found that my HTML encoding is not supporting multipart/form-data.