Hi Friends,
I want to send a file to servlet from an applet which will be sent to another client. [ Sending a file from one user to other through a servlet in my chatprogram ]. Iam getting a security exception and being restricted from accessing a file through an applet. As Iam implementing an encryption mechanism , I must load a file, encrypt it and must send it to servlet, which will be sent to other user.
The below is the code for an applet(encryption not included now).Plz give me your valuable suggestions.
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
public class DispatchFile extends Applet {
public void init() {
String servletURL = "
http://localhost:8080/examples/servlet/DispatchFileServlet";
URL url;
URLConnection con;
BufferedOutputStream bos = null;
BufferedInputStream bis = null;
try {
url = new URL(servletURL);
con = url.openConnection();
bos = new BufferedOutputStream(con.getOutputStream());
bis = new BufferedInputStream(new FileInputStream("give.txt"));
byte[] buff = new byte[2048];
int bytesread;
while(-1 != (bytesread=bis.read(buff,0,buff.length)) ) {
bos.write(buff,0,bytesread);
}
}
catch(final MalformedURLException e) {
System.out.println("Caught Malformed URL Exception");
}
catch(final IOException e) {
System.out.println("Caught IO Exception");
}
finally {
try {
if(bis!=null)
bis.close();
if(bos!=null)
bos.close();
}
catch(Exception e) { }
}
}
}