I am uploading file to a destination by providing filepath. It works fine when file path is like
String filePath = "D:\\location";
But while providing a server location like
String filePath = request.getRealPath("\\10.0.1.18\downloads\upload");
produce error of invalid escape sequence.
Whats wrong in the path ( i have full priveledges to the location) and if wrong how too impliment it correctly.
Thanks for help in advance////
It's a compile-time error, so it can't be to do with permissions etc.
The problem is that you're not escaping the backslashes. You need:
String filePath = request.getRealPath("\\\\10.0.1.18\\downloads\\upload");
Then the contents of the string will be just
\\10.0.1.18\downloads\upload
This is exactly the same as in the first line you showed, where this:
String filePath = "D:\\location";
... will actually create a string with contents of:
D:\location
See section 3.10.6 of the Java Language Specification for more details of escape sequences within character and string literals.
use double slash \\
! It's a special escape pattern. Like \n or \r.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With