Win a copy of Murach's MySQL this week in the JDBC and Relational Databases forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to read files in a directory on a local network

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 22778
130
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried to use that as below:

I got this error:


Any idea?
 
Rob Spoor
Sheriff
Posts: 22778
130
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can only copy files this way, not folders.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic