• 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

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: 22683
128
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: 43028
76
  • 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: 22683
128
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.
 
Your mind is under my control .... your will is now mine .... read this tiny ad
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic