I've a web application on Tomcat 7.0.57 on Windows 8.1 running it as a service, that is instructed to copy a file on a locally network shared directory, for example \\Network_machine\Shared_folder, but it's not able to do so.
I am able to access the shared folder in windows explorer without any authentication, as it has permission to read for everyone. The following code is checking for the directory exist:
String sourceURL = this.servletContext.getInitParameter("sourceURL");
log.debug("---------->Source reports directory : " + sourceURL);
File sourceDir = new File(sourceURL);
log.debug("---------->Source directory exists : "+sourceDir.exists());
if (sourceDir.exists()) {
String files[] = sourceDir.list();
log.debug("----------> Total files in source dir :" + files.length);
List<String> newFiles = new ArrayList<String>(Arrays.asList(files));
newFiles.removeAll(processedFiles);
log.debug("----------> Latest files in source dir :" + newFiles.size());
File file = null;
if (newFiles.size() > 0) {
for (String fileName : newFiles) {
file = new File(sourceURL + Constants.FILE_SEP + fileName);
latestSourceFiles.add(file);
}
}
} else {
log.debug("Source reports directory " + sourceURL + " is not found");
}
Additional Info:
log - Source directory exists is returning 'FALSE'.
As Kenneth says, you need to map the shared folder to a drive and then write directly to that drive.
http://windows.microsoft.com/en-us/windows/create-shortcut-map-network-drive