• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

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: 22802
131
Eclipse IDE Spring 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: 22802
131
Eclipse IDE Spring 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.
 
Arthur, where are your pants? Check under this tiny ad.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic