Hi,
I am trying to read a file sent from client to server. Here is how I am trying it .... -
String filePath = request.getParameter("SelectCSVFile");
-
System.out.println("path:::---> "+filePath);
-
String fileName = filePath.substring(filePath.lastIndexOf("/")+1);
-
System.out.println("File Name:\t"+fileName);
-
-
try {
-
File file = new File(filePath);
-
URL serverURL = new URL(SERVER_URL);
-
URLConnection serverCon = serverURL.openConnection();
-
// 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);//at this line it is throwing the exception
-
It is throwing the exception ..... here is the server log -
-
path:::---> C:/Documents and Settings/harbeer.kadian/My Documents/bugs-2007-09-07.csv//here separators are '/'
-
File Name: bugs-2007-09-07.csv
-
Successfully get the servlet output Stream
-
java.io.FileNotFoundException: C:\Documents and Settings\harbeer.kadian\My Documents\bugs-2007-09-07.csv //here separators are '\'(The system cannot find the path specified)
-
at java.io.FileInputStream.open(Native Method)
-
at java.io.FileInputStream.<init>(FileInputStream.java:106)
-
at com.spi.defecttracker.controller.RequestHandler.uploadCSVFileData(RequestHandler.java:1486)
-
at com.spi.defecttracker.controller.RequestHandler.processRequest(RequestHandler.java:164)
-
at com.spi.defecttracker.controller.RequestHandler.doPost(RequestHandler.java:348)
-
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
-
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
-
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
-
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
-
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)
-
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
-
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
-
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
-
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
-
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
-
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
-
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
-
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
-
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
-
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
-
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
-
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
-
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
-
at java.lang.Thread.run(Thread.java:595)
-
The file path I am sending is using '/'(forward slash) as separator while the path exception is showing is using '\'(backward slash). How is it happening. How can I resolve it.
7 18775
Hi,
I am trying to read a file sent from client to server. Here is how I am trying it .... -
String filePath = request.getParameter("SelectCSVFile");
-
System.out.println("path:::---> "+filePath);
-
String fileName = filePath.substring(filePath.lastIndexOf("/")+1);
-
System.out.println("File Name:\t"+fileName);
-
-
try {
-
File file = new File(filePath);
-
URL serverURL = new URL(SERVER_URL);
-
URLConnection serverCon = serverURL.openConnection();
-
// 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);//at this line it is throwing the exception
-
It is throwing the exception ..... here is the server log -
-
path:::---> C:/Documents and Settings/harbeer.kadian/My Documents/bugs-2007-09-07.csv//here separators are '/'
-
File Name: bugs-2007-09-07.csv
-
Successfully get the servlet output Stream
-
java.io.FileNotFoundException: C:\Documents and Settings\harbeer.kadian\My Documents\bugs-2007-09-07.csv //here separators are '\'(The system cannot find the path specified)
-
at java.io.FileInputStream.open(Native Method)
-
at java.io.FileInputStream.<init>(FileInputStream.java:106)
-
at com.spi.defecttracker.controller.RequestHandler.uploadCSVFileData(RequestHandler.java:1486)
-
at com.spi.defecttracker.controller.RequestHandler.processRequest(RequestHandler.java:164)
-
at com.spi.defecttracker.controller.RequestHandler.doPost(RequestHandler.java:348)
-
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
-
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
-
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
-
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
-
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)
-
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
-
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
-
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
-
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
-
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
-
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
-
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
-
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
-
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
-
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
-
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
-
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
-
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
-
at java.lang.Thread.run(Thread.java:595)
-
The file path I am sending is using '/'(forward slash) as separator while the path exception is showing is using '\'(backward slash). How is it happening. How can I resolve it.
Hi madhoriya22!
Is there any specific reason known to you, why -
System.out.println("Successfully set the header"); // line 15
-
doesn't create an output? Also, what does -
System.out.println("File exists: " + file.exists());
-
say? And why are you using '/' as a file separator, when the standard file separator under Windows is '\\'?
Greetings,
Nepomuk
*QUESTION TO THE ADMINS & CO: What is this code-tag-bug? It didn't let me create a java-code-section with some code but it did allow a text-code-section with the same code. Weird...*
..
Greetings,
Nepomuk
*QUESTION TO THE ADMINS & CO: What is this code-tag-bug? It didn't let me create a java-code-section with some code but it did allow a text-code-section with the same code. Weird...*
The code tags bug (as I know it) is that when you quote a post with long lines of code posted under code tags then chances are high that that post that you make will appear as a blank post.
Edit: As evidenced by snowfall's second post here. The first post was also hit by the bug but I removed the quote from it through the edit facility.
Hi madhoriya22!
Is there any specific reason known to you, why -
System.out.println("Successfully set the header"); // line 15
-
doesn't create an output? Also, what does -
System.out.println("File exists: " + file.exists());
-
say? And why are you using '/' as a file separator, when the standard file separator under Windows is '\\'?
Greetings,
Nepomuk
*QUESTION TO THE ADMINS & CO: What is this code-tag-bug? It didn't let me create a java-code-section with some code but it did allow a text-code-section with the same code. Weird...*
Hi nepomuk,
By mistake I copied that line. //line 15 -
System.out.println("File exists: " + file.exists());
-
and its not working .. means not able to find the file .....
Thats what I want to ask ......
How can i make it to find the file in client's system(The file I am supplying is on client's machine).
'/' separator I was using because while while getting the file name from the path supplied ... it was giving compile time error here -
String fileName = filePath.substring(filePath.lastIndexOf("/")+1);//here it was not taking back slash(\)
-
But now I have resolved it .... by doing like this .. -
String fileName = filePath.substring(filePath.lastIndexOf("\\")+1);
-
So pls give ur suggestions on that ..
Hi nepomuk,
By mistake I copied that line. //line 15 - System.out.println("File exists: " + file.exists());
-
and its not working .. means not able to find the file .....
OK, that reduces the possibilities of what the mistake might be, as it's something with the Path.
How can i make it to find the file in client's system(The file I am supplying is on client's machine).
This program is running on the client's computer, isn't it? If it's running on server side, you'll not be able to do it like that. (And I don't know, how you could do it at all with Java, but maybe someone else does?)
'/' separator I was using because while while getting the file name from the path supplied ... it was giving compile time error here - String fileName = filePath.substring(filePath.lastIndexOf("/")+1);//here it was not taking back slash(\)
But now I have resolved it .... by doing like this .. - String fileName = filePath.substring(filePath.lastIndexOf("\\")+1);
-
The path on a windows system is normally separated with '\\', but as far as I know, '/' is possible. However, new File("this.txt").getAbsolutePath() for example will supply a Path using '\\'.
If you don't know, what separator will be used, you can't do it quite like that - you'll have to check: -
String fileName;
-
if(filePath.indexOf('/') != -1) fileName = filePath.substring(filePath.lastIndexOf("/")+1);
-
else if(filePath.indexOf('\\') != -1) fileName = filePath.substring(filePath.lastIndexOf("\\")+1);
-
else fileName = filePath; // just to make sure
-
or (and this might solve your problem for you): -
filePath = filePath().replace('\\', '/');
-
String fileName = filePath.substring(filePath.lastIndexOf("\\")+1);
-
With this, you make sure, that there will only be '\\'s and no '/'s in your path.
Does that help?
Greetings,
Nepomuk
OK, that reduces the possibilities of what the mistake might be, as it's something with the Path.
This program is running on the client's computer, isn't it? If it's running on server side, you'll not be able to do it like that. (And I don't know, how you could do it at all with Java, but maybe someone else does?)
The path on a windows system is normally separated with '\\', but as far as I know, '/' is possible. However, new File("this.txt").getAbsolutePath() for example will supply a Path using '\\'.
If you don't know, what separator will be used, you can't do it quite like that - you'll have to check: -
String fileName;
-
if(filePath.indexOf('/') != -1) fileName = filePath.substring(filePath.lastIndexOf("/")+1);
-
else if(filePath.indexOf('\\') != -1) fileName = filePath.substring(filePath.lastIndexOf("\\")+1);
-
else fileName = filePath; // just to make sure
-
or (and this might solve your problem for you): -
filePath = filePath().replace('\\', '/');
-
String fileName = filePath.substring(filePath.lastIndexOf("\\")+1);
-
With this, you make sure, that there will only be '\\'s and no '/'s in your path.
Does that help?
Greetings,
Nepomuk
Hi,
Thanks buddy .... I got your point :)
Does anyone know how to get the file from client to server?
Hi,
Thanks buddy .... I got your point :)
Does anyone know how to get the file from client to server?
If you're prepared to use another language for that task, this thread might help you.
Greetings,
Nepomuk
If you're prepared to use another language for that task, this thread might help you.
Greetings,
Nepomuk
Hi,
I can not use other language. I have to do this in java. I wish I could make use of MultipartRequest.. But my html form is not using the encoding type which is required for multipart/form-data.
Anyway thanks for your suggestion :)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: ian maclure |
last post by:
I'm writing a client-server app.
Client controls Server which in turn configures and controls
a bunch of hardware.
I want to be able to start the server from my client.
Now in C/C++ one could...
|
by: Arpan |
last post by:
Consider the following code snippet:
<%
Dim objFSO,objOpenFile,strPath
strPath=Server.MapPath("ADList1.txt")
Set objFSO=Server.CreateObject("SCRIPTING.FILESYSTEMOBJECT")
Set...
|
by: CT |
last post by:
Hi,
This might seem like a basic question but I have some doubts, please
humour me.
I have a client-server application using java where each client on
each machine needs to directly...
|
by: Pedro Bautista |
last post by:
Status: Unsolved and puzzling
Steps to reproduce the error:
1.- Delete IUSER from server
2.- Reboot server (OS rebuilds IUSR)
3.- Assign IUSR read and execute permission on web folder
and...
|
by: Christian Wilhelm |
last post by:
Hi!
I'm trying to call a Java WebService out of a .net Client. There are two
Methods, one Method requires one Parameter of type Parameter, the other
Method requires one Parameter of type...
|
by: archana |
last post by:
Hi all,
I am new to asp.net (learning phase).
I have to develop application in asp.net to read file from client pc
and display statistics of that file to client.
So my question is that to...
|
by: praveen2gupta |
last post by:
Hi
In my application i wants to read a file through a applet. I am using jsp.etc, . when application is loaded through web server on the another computer. The applets is downloaded and starts...
|
by: Cybelle |
last post by:
please anyone can help me to solve this stuff, this is our final ., theres an error and i dont know how to solve it.,
import java.awt.*;
import java.awt.event.*;
import java.net.*;...
|
by: diegoblin |
last post by:
Hi, i kind of new to java and i want to transfer a file between a server and a client.
I know i have to use InputStream and OutputStream, but i don't know how to do it properly.
So far i think i've...
|
by: Elaine121 |
last post by:
Hi i've been batteling for hours and can't seem to find the problem. When my server runs and I press the connect button the gui freezes until the client gui is terminated.. only then the gui becomes...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |