简体   繁体   English

如何在Java中从文件服务器访问目录?

[英]how to access directory from file server in java?

HI... 嗨...

Currently I m working in a application in which application allows to access directory (which contains some files) from file server to Application (client). 目前,我正在一个应用程序中工作,在该应用程序中,应用程序允许从文件服务器访问应用程序(客户端)的目录(其中包含一些文件)。

I tried following code.. 我尝试了以下代码。

URL url=("http://192.168.5.555/file-server/user/images/");
URI uri=url.toURI();
File list[];

list= new File(uri).listFiles();

But its thrown java.lang.IllegalArgumentException Exception. 但是它抛出了java.lang.IllegalArgumentException异常。

I don't know how this happen? 我不知道怎么回事?

I simply access images directory from the given URL (file server). 我只是从给定的URL(文件服务器)访问images目录。

Help me... 帮我...

That isn't going to work. 那是行不通的。 The java.io.File operates on the local disk file system only, ie on URI's starting with file:// only. java.io.File仅在本地磁盘文件系统上运行,即在以file://开头的URI上运行。 It would otherwise indeed going to be too easy to leech files from places where you aren't allowed to do so. 否则,从不允许的地方窃取文件确实非常容易。

Check if the server in question supports FTP, then you can just use FTPClient#listFiles() for this. 检查相关服务器是否支持FTP,然后就可以使用FTPClient#listFiles() If it doesn't, but it supports directory listing, then you need to parse the HTML response containing the directory listing with a HTML parser like Jsoup and then refire a new request on every found link. 如果不支持,但它支持目录列表,则需要使用HTML解析器(如Jsoup)解析包含目录列表的HTML响应,然后在找到的每个链接上重新发起新请求。

If it doesn't support FTP or directory listing, then you're lost and you're probably trying to do bad things. 如果它不支持FTP或目录列表,那么您会迷路,并且您可能正在尝试做坏事。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM