what is the best way to send a file?
i am writing a program and i want to transfer a file from a client class to a server class... what is the best way to do that?
convert the file to bytes using the following
File file=new File("jobs.xml");
byte buffer[]=newbyte[(int)file.length()];
try{
BufferedInputStream input=new BufferedInputStream(new FileInputStream("jobs.xml"));
input.read(buffer,0,buffer.length);
input.close();
}catch(Exception e){//DIORTHOSE TA MSGS
System.out.println("reading jobs.xml->buffer: "+e.getMessage());
e.printStackTrace();
}
firstServerRef.translationService(theCallbackObjectRef, buffer);
for a reason i dont like that i am reading the file again to put it in the buffer and send the buffer... are my worries reasonable or not? is there any other better way to do that?
[1371 byte] By [
panosjava] at [2007-11-26 12:16:55]

# 4
> Use a smaller buffer, repeatedly read and
> write, and print the exception's stack trace.
>
> What do you mean by reading again, by the way? I only
> see you reading the file once.
hmm you mean use a smaller buffer and call the function with the smaller buffer many times in a while?
the client and the server are not on a single machine and i want to call the function only once... could you clarify the thing that you said..
yes you are correct that you see only one reading because i haven't pasted the rest of the code which is sth like...
FileWriter fw = new FileWriter("jobs.xml");
ObjectOutputStream out = xstream.createObjectOutputStream(fw);
// out.writeObject(new Jobb("ougk2", "Walnes",null));
for(int i=0;i<nameOfServices.length;i++){
Jobb translationJob=new Jobb();
//find the service !
NameComponent nc = new NameComponent(nameOfServices[i], " ");
// Resolve the object reference in naming
NameComponent path[] = {nc};
//create a ref for the servant of the service
ServiceOperations theRemoteObjRef = ServiceHelper.narrow(ncRef.resolve(path));
// JobOperations theRemoteObjRef = JobHelper.narrow(ncRef.resolve(path));
translationJob.setObjServerRef(theRemoteObjRef.toString());
if(i==0){ //this is the first job
translationJob.setForTranslation(wordForTranslation);
firstServerRef=theRemoteObjRef;
}
out.writeObject(translationJob);
}
out.close();
File file=new File("jobs.xml");
byte buffer[]=new byte[(int)file.length()];
try {
BufferedInputStream input=new BufferedInputStream(new FileInputStream("jobs.xml"));
input.read(buffer,0,buffer.length);
input.close();
} catch(Exception e) {//DIORTHOSE TA MSGS
System.out.println("reading jobs.xml->buffer: "+e.getMessage());
e.printStackTrace();
}
firstServerRef.translationService(theCallbackObjectRef, buffer);
which i believe is bad....