File transfer in RMI
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   sameer_mohta
Posted On:   Friday, January 11, 2002 02:34 AM

How to transfer a text file from server to client.
I am trying to transfer a text file from server to client using File objects. but i am not getting success. so how can we transfer a text file without going into the Socket programming and streams.

Re: File transfer in RMI

Posted By:   Anonymous  
Posted On:   Monday, January 14, 2002 06:36 AM

In Java, a File Object simply represents a possibly existing file on the file system.



If you create a file object like this:


File f = new File ( "c:\test.txt" );


and the file "c: est.txt" doesn't exist, this will throw no exception (but f.exists ( ) will tell you so).



If you want to work with a file's content, you'll ask an InputStream for it, and only then you'll really access the file.



What you can do to solve your problem, is to read the file on the server side, store it's content (in a String, byte array, or whatever ...) and pass the content to the client.



This has to be done, because the remote machine can't access the local machine's file system.



This can be implemented by putting a method in you remote interface like this:


byte[] getFileContents ( String fileName ) throws RemoteException;


if you then implement this method on the serverside and return a byte array, you can write a new file on the client side, or keep the data in memory, according to your needs ...





Regards,


G√ľnther.


http://www.javacoding.net
About | Sitemap | Contact