Total members 9951 | Gratitudes |It is currently Sat Feb 11, 2012 11:00 am Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 5 posts ] 
Author Question
 Question subject: copy files from applet server to client
PostPosted: Thu Jul 30, 2009 12:21 pm 
Offline
Newbie
User avatar

Joined: Fri Mar 27, 2009 2:57 pm
Posts: 2
Has thanked: 0 time
Have thanks: 0 time

hi,

i have the following code to copy from server clinet.

i call the methods copy() ans copyprop() in my actual applet code in the init().


Code:
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.channels.FileChannel;

public class testsett {

   void copy()
   {
      try{
         File inputFile = new File( "c:\\winnt\\system32\\testall.dll");
         URL copyurl;
         InputStream outputFile;
         copyurl=new URL("http://<server ipaddress>:8080/Samples/testall.dll");
         outputFile=copyurl.openStream();
         FileOutputStream out = new FileOutputStream(inputFile);
         int c;
         while ((c = outputFile.read()) != -1)
            out.write(c);
         outputFile.close();
         out.close();
      }catch(Exception e){
         System.out.println("Failed to Copy File from server");
         e.printStackTrace();
      }
      }
      
      void copyprop()
      {
         try{
            File inputFile = new File( "c:\\winnt\\system32\\propert.properties");
            URL copyurl;
            InputStream outputFile;
            copyurl=new URL("http://<server ipaddress>:8080/Samples/propert.properties");
            outputFile=copyurl.openStream();
            FileOutputStream out = new FileOutputStream(inputFile);
            int c;
            while ((c = outputFile.read()) != -1)
               out.write(c);
            outputFile.close();
            out.close();
         }catch(Exception e){
            System.out.println("Failed to Copy File from server");
            e.printStackTrace();
         }
   }

   public static void main(String args[]) throws IOException
   {
      testsett ts = new testsett();
      ts.copyprop();
      ts.copy();
   }
}



but this code is not working..
is there any modifications to be made to this code to copy file from applet server to client.

thank you in advance


TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: copy files from applet server to client
PostPosted: Fri Jul 31, 2009 9:28 am 
Offline
Mastermind
User avatar

Joined: Tue Mar 27, 2007 10:55 pm
Posts: 2103
Location: Earth
Has thanked: 39 time
Have thanks: 56 time
hey , i think you want to code a FTP java Client . right . to Read a file from your server you need to have security policy . Did you run it . what is the output of it .

You can use this to get user home :


Code:
System.getProperty("user.home" );

_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )


TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: copy files from applet server to client
PostPosted: Fri Jul 31, 2009 12:53 pm 
Offline
Newbie
User avatar

Joined: Fri Mar 27, 2009 2:57 pm
Posts: 2
Has thanked: 0 time
Have thanks: 0 time
hi .

i just found the solution

1. <%@ page language="java" %>
2. <html>
3. <head>
4. <title>Welcome JSP-Applet Page</title>
5. </head>
6. <body>
7.
8. <applet code="testapp.class" width="1000" height="190">
9. <param name="path" value=<%="\""+getServletContext().getRealPath("/")+"\""%> />
10. <param name="file" value=<%="testall.dll"%> />
11. <param name="prop" value=<%="propert.properties"%> />
12.
13. </applet>
14.
15. </body>
16. </html>



1. public class testapp extends Applet implements ActionListener{
2.
3. String path = null;
4. String file = null;
5. String prop = null;
6.
7. public void init()
8. {
9. path = getParameter("path");
10. file = getParameter("file");
11. prop = getParameter("prop");



1. try{
2. File inputFile = new File( "c:\\winnt\\system32\\propert.properties");
3. URL copyurl;
4. InputStream outputFile;
5. copyurl=new URL(getCodeBase(),prop);
6. outputFile=copyurl.openStream();
7. FileOutputStream out = new FileOutputStream(inputFile);
8. int c;
9. while ((c = outputFile.read()) != -1)
10. out.write(c);
11. outputFile.close();
12. out.close();
13. }catch(Exception e){
14. System.out.println("Failed to Copy properties from server");
15. e.printStackTrace();
16. }
17.
18. try{
19. File inputFile = new File( "c:\\winnt\\testall.dll");
20. URL copyurl;
21. InputStream outputFile;
22. copyurl=new URL(getCodeBase(),file);
23. outputFile=copyurl.openStream();
24. FileOutputStream out = new FileOutputStream(inputFile);
25. int c;
26. while ((c = outputFile.read()) != -1)
27. out.write(c);
28. outputFile.close();
29. out.close();
30. }catch(Exception e){
31. System.out.println("Failed to Copy dll from server");
32. e.printStackTrace();
33. }




hope this may help others

thank you


TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: copy files from applet server to client
PostPosted: Fri Jul 31, 2009 1:08 pm 
Offline
Mastermind
User avatar

Joined: Tue Mar 27, 2007 10:55 pm
Posts: 2103
Location: Earth
Has thanked: 39 time
Have thanks: 56 time
thank you for sharing the solution with us .

_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )


TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: copy files from applet server to client
PostPosted: Sun Aug 02, 2009 9:08 am 
Offline
Newbie
User avatar

Joined: Sun Aug 02, 2009 9:05 am
Posts: 1
Has thanked: 0 time
Have thanks: 0 time
great thanks for the info

taux credit consommation
- Taux credit consommation, Un organisme de credit, ou banque de nouvelle generation, offre du credit
consommation


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 5 posts ] 
Quick reply


  


 Similar topics
 Topic title   Forum   Author   Comments 
 script for including files  PHP  malik4you  1
 How to download and save .mov files from this website ?  General Discussion  Sandy1984  7
 Ajax Source code to Suggest application with JSP Server side  AJAX  msi_333  5
 RMI EXAMPLE FOR CLIENT SERVER ARCHITECTURE CODE ?????  Java  Anonymous  0
 client server problem  Java  bablu1790  0

All times are UTC [ DST ]


Users browsing similar posts

Users browsing this forum: Google [Bot] and 4 guests



Jump to:  
Previous Question | Next Question 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team