could you show me the
java policy file you are using or the directory structure you have or the drive\folder you want to save to?
None of those things that you, are required. I have made an example in 2003 that was an applet and read/wrote to a file on my PC from javaserver.com and geocities site.
simply read file from server and write to the destination file in the folder ie the path you want... Simple I/O.. thats it!
Part of Applet sample code can be
[code]
URLConnection uc = new URL("http:// your server address where
servlet will stream out file name and bytes and the url may have get request of file name or send me file request which the servlet will parse ").openConnection();
uc.setDoOutput(true);
uc.setDoInput(true);
uc.setAllowUserInteraction(false);
DataOutputStream dos = new DataOutputStream(uc.getOutputStream());
// The POST line, the Accept line, and
// the content-type headers are sent by the URLConnection.
// We just need to send the request for a specific file or just file as per requirement
dos.writeBytes("SendMeFile".toBytes());
dos.close();
// Read the server response
DataInputStream dis = new DataInputStream(uc.getInputStream());
BufferedReader br = new BufferedReader (new InputStreamReader(dis));
String nextline;
while ((nextline = br.readLine()) != null) {
System.out.println(nextline);
}
dis.close();
br.close();
[/close]
And Server code sample can be in the get or post method can be
request.getParamater();
Do I/O on computer for the requested file or for file request according to your requirement
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class MyServlet extends HttpServlet {
String name = "content.txt"; // Demo text file to send. It could be a binary file like image or c++ compiled file or exe...
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
String file = getServletContext( ).getRealPath(name);
res.setContentType("text/plain");// set other content type if required
OutputStream out = res.getOutputStream( );
returnFile(file, out);
}
public static void returnFile(String filename, OutputStream out)
throws FileNotFoundException, IOException {
InputStream in = null;
try {
in = new BufferedInputStream(new FileInputStream(filename));
byte[ ] buf = new byte[4 * 1024]; // 4K buffer
int bytesRead;
while ((bytesRead = in.read(buf)) != -1) {
out.write(buf, 0, bytesRead);
}
}
finally {
if (in != null) in.close( );
}
}
}
Thanks,
Maki Jav