Java - How to view files on a mapped network drive?
I am trying to connect to a mapped drive (sharepoint) to create a list of the files that exist.
So I have this code that works great when listing files on my local PC:
public static void main(String[] args) {
// Directory path here
String path = "/";
String files;
File folder = new File(path);
File[] listOfFiles = folder.listFiles();
for(int i = 0; i < listOfFiles.length; i++){
if(listOfFiles[i].isFile()){
files = listOfFiles[i].getName();
System.out.println(files);
}
}
}
When path = "/" it displays all files on my local C: drive. Now I would like to know if there is a way to adapt this to display the files of a mapped network drive (for Y for example).
+3
source to share
1 answer
if your os are windows you can use \\ Server \ shared_folder
public static void main(String[] args) {
// Directory path here
String path = "\\\\server\\shared_folder";
String files;
File folder = new File(path);
File[] listOfFiles = folder.listFiles();
for(int i = 0; i < listOfFiles.length; i++){
if(listOfFiles[i].isFile()){
files = listOfFiles[i].getName();
System.out.println(files);
}
}
}
+3
source to share