Total members 11894 |It is currently Sun Nov 24, 2024 1:20 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





hi,

i have the following code to copy from server client(Applet application).

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


java 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




Author:
Newbie
User avatar Posts: 2
Have thanks: 0 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" );


_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time

hi .

i just found the solution

html code
<%@ page language="java" %>  
<html>
<head>
<title>Welcome JSP-Applet Page</title>
</head>
<body>

<applet code="testapp.class" width="1000" height="190">
<param name="path" value=<%="\""+getServletContext().getRealPath("/")+"\""%> />
<param name="file" value=<%="testall.dll"%> />
<param name="prop" value=<%="propert.properties"%> />

</applet>

</body>
</html>



public class testapp extends Applet implements ActionListener{

java code
String path = null;  
String file = null;
String prop = null;

public void init()
{
path = getParameter("path");
file = getParameter("file");
prop = getParameter("prop");



try{
File inputFile = new File( "c:\\winnt\\system32\\propert.properties");
URL copyurl;
InputStream outputFile;
copyurl=new URL(getCodeBase(),prop);
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 properties from server");
e.printStackTrace();
}

try{
File inputFile = new File( "c:\\winnt\\testall.dll");
URL copyurl;
InputStream outputFile;
copyurl=new URL(getCodeBase(),file);
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 dll from server");
e.printStackTrace();
}





hope this may help others


Author:
Newbie
User avatar Posts: 2
Have thanks: 0 time

thank you for sharing the solution with us .

_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 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



Author:
Newbie
User avatar Posts: 1
Have thanks: 0 time

I prefer Java FTP :
finished-projects/ftp-server-and-ftp-client-t1179.html
java-tutorials/using-ftp-in-java-t7673.html

_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 6 posts ] 

  Related Posts  to : copy files from applet server to client
 client server client     -  
 FTP Server and FTP Client     -  
 UDP server and UDP client (J2SE)     -  
 client server problem     -  
 Client-Server Forum discussion     -  
 how to connect client on one machine with server     -  
 need java client/server code     -  
 RMI EXAMPLE FOR CLIENT SERVER ARCHITECTURE CODE ?????     -  
 A Simple Client Server Multicasting     -  
 Client Server Mobile to PC Application     -  



Topic Tags

Java Applet
cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com