开发者

signed applet, downloading file from server and place it in the file system

I have signed applet, I want to download any kind of file from the server and place it in the file system using the applet.

P开发者_开发知识库lease give some pointer.

Thanks in advance.


You'll have to write servlet for this. Because servlets can access to server local file system and get files you want for your applet :) Make bound like a

applet <-servlet<-server

Good luck


The applet need to be signed to access the file system.

 public String downloadFile(final String filename) {
    return (String)AccessController.doPrivileged(new PrivilegedAction(){
        public Object run() {       
          try {
                // downloadURL is the server URL say http://localhost/downloads
                // filename is a file want to download from the server 
                // localpath is the path you want to download in the file system
                URL finalURL = new URL(downloadURL + filename);
                ReadableByteChannel rbc = Channels.newChannel(finalURL.openStream());
                FileOutputStream fos = new FileOutputStream("/"+localpath.replace("\\","/") +  filename);
                fos.getChannel().transferFrom(rbc, 0, 1 << 24);
                fos.close();
            return "true";
          }catch (ConnectException ce) {
              e.printStackTrace();
              return "false";
          } 
          catch (Exception e) {
            e.printStackTrace();
            return "false";
          }
        }
      });
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜