DmitryB
DmitryB

Reputation: 1179

How to access a filesystem in java?

I need to iterate a folder on local machine from the server to parse some files. Is it real? If it's true, please, advise me how to do it.

Upvotes: 7

Views: 7266

Answers (4)

cl-r
cl-r

Reputation: 1264

You can also have a glance at the new package nio.2 in Java 7, with tutorial here.

Many new and powerful things.

Upvotes: 2

user219882
user219882

Reputation: 15844

I prefer Commons VFS. It can handle local filesystems, SFTP and many others. All with the same code - you just change paths to files.

FileSystemManager fsManager = VFS.getManager();
FileObject directory = fsManager.resolveFile("path/to/dir");
FileObject[] files = directory.findFiles(fileSelector);

for (FileObject file : files) {
    // do something
}

Upvotes: 7

CloudyMarble
CloudyMarble

Reputation: 37566

Try to implement a client server application where the server part is installed on your client PC and privides the clietn part (which will run on the Server PC) with the needed information. Alternativly you can use FTP Server on the client machine and access it from the server when needed.

Upvotes: 0

ControlAltDel
ControlAltDel

Reputation: 35011

If you can connect via SSH, FTP, or FTPS this can be done fairly easily. If you are talking about HTTP, the server must be set to show directories = true, and you will have to parse the http response for the directory to get the files names.

Upvotes: 0

Related Questions