This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Problem with Windows Folders having Spaces Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Problem with Windows Folders having Spaces" Watch "Problem with Windows Folders having Spaces" New topic
Author

Problem with Windows Folders having Spaces

santosh batta
Ranch Hand

Joined: Jun 04, 2012
Posts: 32
Hi,
My requirement is to transfer files (download/upload) from a remote windows shared drive. I'm using JCIFS API to achieve it. I'm able to connect & download files from there. The issue is when the folder name on the remote machine has spaces, my code is failing with "Failed to connect to server" error.
Below is the code snippet


When executed, I'm getting SMB exception. When tried with folders without spaces, its working absolutely fine. Would you please help me out?

jcifs.smb.SmbException: Failed to connect to server
java.net.UnknownHostException: \\HostIP\Trans-serv\1_NBWCPSUP\Test Files\My Folder-Cycle 1\hi.txt
at jcifs.UniAddress.getAllByName(UniAddress.java:315)
at jcifs.smb.SmbFile.getFirstAddress(SmbFile.java:862)
at jcifs.smb.SmbFile.connect(SmbFile.java:951)
at jcifs.smb.SmbFile.connect0(SmbFile.java:880)
at jcifs.smb.SmbFile.open0(SmbFile.java:972)
at jcifs.smb.SmbFile.open(SmbFile.java:1006)
at jcifs.smb.SmbFileInputStream.<init>(SmbFileInputStream.java:73)
at jcifs.smb.SmbFileInputStream.<init>(SmbFileInputStream.java:65)
at WinFileTransfer.main(WinFileTransfer.java:37)
Ivan Jozsef Balazs
Rancher

Joined: May 22, 2012
Posts: 867
    
    5


The unescaped blackslashes inside a String literal seem problematic to me, though the file name reported in the error message seems to be correct. Strange.
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4167
    
  21

You have to put the entire path in quotes (escaped double quotes) to make sure windows keeps the path together as one term instead of splitting it at the spaces.


Steve
santosh batta
Ranch Hand

Joined: Jun 04, 2012
Posts: 32
Hi Steve,
Thanks for your response. I've figured it out. The problem is with the string "smb://". For some reason, its not accepting this as the correct URL format. I've modified it as below

"smb:"+"//"+hostIP+....

and it worked.

The other problem, I forget to address is the File transfer rate. It is taking approximately 2 min. to download 9MB file which I feel is very less. I've tried several ways with changing the buffer size, but it doesn't help significantly. Is there any way to improve the performance?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19654
    
  18

santosh batta wrote:

Semi unrelated, but that line is wrong. 0 is a valid return value, and it does not indicate you're done. Change it into != -1, > -1 or >= 0.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
santosh batta
Ranch Hand

Joined: Jun 04, 2012
Posts: 32
Hi Rob,
When I change the condition to >=0 or != -1 , the performance still got worse. Previously it was taking 2 min. to download 9MB file & now its taking 5 min.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

santosh batta wrote:Hi Rob,
When I change the condition to >=0 or != -1 , the performance still got worse. Previously it was taking 2 min. to download 9MB file & now its taking 5 min.


Most likely it was taking 2 min. to download part of a 9MB file, until read() returned 0. Even if you got the whole file that time, the code is wrong and isn't guaranteed to work.

If performance is a problem, you might try wrapping your InputStream in a BufferedInputStream, if you're not already doing so.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with Windows Folders having Spaces
 
Similar Threads
Compress .zip using Java
J2me:Question about HttpConnection
neep help - files inside folder structure
how to Unzip folder
Java And OpenDocument Files