Copy a file from local drive to network drive!
[nobr]The subject says it all but I'll explain. I have a web application that runs on a tomcat and mysql. I have a bunch of clients in a local network that uses the application.
Server is running Windows 2003 server and clients are running windows XP.
On a client request a file is created on the server in "temp" folder. The file name is "justAFile.txt".
On the client pc a folder "temp" is shared for reading/writing.
What I want is the server to take the IP address of the client, and then based on that address to copy the file "justAFile.txt" to it (for example "\\192.168.0.20\temp\" - that is the client address).
I have the address of the client:
String userAddress = request.getRemoteAddr();
I use this code:
FileOutputStream outFile;
PrintStream p;
String bonFileName = (justAFile.txt");
String destinationFileWithPath = ("\\\\192.168.0.20\temp\\skladPrint\\"+bonFileName);
try{
outFile =new FileOutputStream(destinationFileWithPath);
p =new PrintStream( outFile );
p.println ("a textto be written on a file");
p.close();
}catch (Exception e){
%>Error writing to file<br><%
}
This code can create a file on a local drive with no problems, but when I try on a network drive it fails. Even for testing purposes I set the shared folder to a maped drive "Z:", and again no luck.
I've spend all my day till now in reading articles in inet, but haven't found one that will solve the problem.
I also tried creating a batch file (exec.bat) that has in it:
move \temp\*.txt \\192.168.0.20\temp
and then executing it with:
String[] executeCommand1 ={"cmd.exe","/c","\\temp\\exec.bat"};
Process p1 = Runtime.getRuntime().exec(executeCommand1);
p1.waitFor();
But again no luck. When I execute the file from command prompt, it moves the file to the shared folder, but when I start it from the java application with the posted code, it DOES NOT move the file...
Any help will be appreciated...[/nobr]

