开发者

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

开发者 https://www.devze.com 2023-04-11 02:33 出处:网络
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.

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

精彩评论

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