• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to read files in a directory on a local network

 
Nasim Salehi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I need to read some folders from directory on machines inside a local network and copy them in another location,In fact I'm deploying some folders to a central location manually,
I'm wondering if I should use FileInputStream and something like this?
I tried this one and I can read files on my local machine,
here's the code I used for reading all filenames in a directory:


but when I want to read from a directory on another machine in local network I got this error:


Any help would be great.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We can't tel just which line threw that error from here, but I'd guess it's because of this bit from the doc on File.listFiles(): Returns null if this abstract pathname does not denote a directory, or if an I/O error occurs.

What's the filename string you're passing to new File()?
 
Nasim Salehi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your attention,
the string I've passed to the new file() method for reading from local network is something like this: "\\mycomputerName\folderName" which mycomputerName is name of my computer in network and folderName is name of the folder i want to read list of files in.I really have no idea if such addressing across a local network could be correct or there's another way?
 
Rob Spoor
Sheriff
Posts: 20822
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can the user that is running the program access this folder?

And in Java, do you specify it as follows: "\\\\mycomputerName\\folderName"? You'll need the 4 backslashes at the start, because \ is the Java escape character and \\ will indicate only a single backslash.
 
Nasim Salehi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot dear Rob!
It works!
I'd forgot the way java deals with backslashes.
Now,do you have any idea for copying files ?
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Jakarta Commons IO library has a number of useful routines for file copying in the IOUtils class. Might be easier to use those than to roll your own.
 
Nasim Salehi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried to use that as below:

I got this error:


Any idea?
 
Rob Spoor
Sheriff
Posts: 20822
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can only copy files this way, not folders.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!