Joining remote paths in Java

Posted by Mickael Marrache on Stack Overflow See other posts from Stack Overflow or by Mickael Marrache
Published on 2012-05-09T13:55:43Z Indexed on 2012/07/02 9:16 UTC
Read the original article Hit count: 243

Filed under:
|

I'm using the FTP library provided by Apache (commons-net). I want to check if a file exists on the FTP server so I use the listFiles method of FTPClient:

ftpClient.listFiles(remoteFileDir + "\\" + fileName);

The current directory is the FTP server root directory. So, the value of remoteFileDir is a path relative to this root directory.

My question concerns the merge between the remote directory path and the file name. What is the right way to do it? For a local file, I would do:

File file = new File(remoteFileDir,fileName);

but here it doesn't work since when I call file.getAbsolutePath(), I get an absolute path for the file in the local current directory which is not what I want. Also, I guess the merging has been done according to my local environment.

PS: I looked at How are paths determined on a remote machines? but it doesn't help me.

Thanks

© Stack Overflow or respective owner

Related posts about java

Related posts about path