The Artima Developer Community
Sponsored Link

Java Answers Forum
how to use beans for file copy on another machine on LAN?

4 replies on 1 page. Most recent reply: Sep 1, 2005 9:35 PM by vsharma

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 4 replies on 1 page
vsharma

Posts: 7
Nickname: vps05
Registered: Aug, 2005

how to use beans for file copy on another machine on LAN? Posted: Sep 1, 2005 6:53 AM
Reply to this message Reply
Advertisement
hi

everybody i am stuck.
i am first time using beans.
can anybody please tell me how a file can be copied from one machine to another machine usingg beans.
i dont want to use servlets or JSP.

regards
vps


Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: how to use beans for file copy on another machine on LAN? Posted: Sep 1, 2005 7:04 AM
Reply to this message Reply
I'm lost you want to transfer A File of what type? (Anyways,
that doesn't matter).

If your passing it across a Network it would usually be wise to
Serialize your Bean, simply make all your beans implement the
Serializable interface.

Then simply pass the bean across the network. Implement
a Server that resides on the receiving machine, the Server
should be able to write the file to the local file system
(come to think of it I think it does matter what type of a
file).

vsharma

Posts: 7
Nickname: vps05
Registered: Aug, 2005

Re: how to use beans for file copy on another machine on LAN? Posted: Sep 1, 2005 7:06 AM
Reply to this message Reply
It is a text file.

can u plz give me some link
where i could find related stuff.
or briefly explain the things

Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: how to use beans for file copy on another machine on LAN? Posted: Sep 1, 2005 7:42 AM
Reply to this message Reply
Fortunately I just knocked off so I can give you a tad more detail.

OK I'm assuming you know what Beans are? Pretty much just container
classes (a bunch of getters and setters - well atleast at the basic
level.

If your simply trying to stick in a plain text file that should be
one of the easiest things you can do.

Your bean will have two simple methods or possibly two others to
toy with the name property.

public class MyBean implements Serializable{
   private String file;
   private String name;
   public void setFile(String file){
      this.file = file;
   }
   
   public String getFile(){
      return this.file
   }
   
   public void setName(String name){
      this.name = name;
   }
   
   public String getName(){
      return this.name;
   }
}



OK now comes the Magic. You create another class that does the
reading of this File and returns a String so as you can set whatever
bean you create (I'm assuming the file is not too large).

// this is psedo code
public class FileReader{
   public String getLongStringFromFile(String fileName){
      BufferedReader br = new BufferedReader(TakingInInputStreamReader_Which_YOU_CHOOSE_TO_SET_UP);
      String my_gigantic_string = "";
      while(br_is_not_at_file_end){
         my_gigantic_string = my_gigantic_string+br.readLine();
      }
      return my_gigantic_string;
   }
}


Don't have much time to do the rest of the explaining coz I have to go home in a bit, but what
happens next is you create a third class that will kind of be like your controller.

Declare a bean there, do your file reading set the file property via

setFile(myFileReader.getLongStringFromFile);

Fly to the other computer via another class you create (A client) - google Java Client Server Tutorial.

On the other end write a class Server (compiled on the Server - receiving computer),
this Server class should have at least 1 method that writes to the local File System.

A Servlet might do the trick actually. If its able to deserialize the bean then your
in business. Google Java Serializable tutorial. That way you will get the name
property and use your write method in the server to write to the file.

Good luck, gotta jet.
Spike

vsharma

Posts: 7
Nickname: vps05
Registered: Aug, 2005

Re: how to use beans for file copy on another machine on LAN? Posted: Sep 1, 2005 9:35 PM
Reply to this message Reply
hi

thanx alot.
its helping me.

regards
vps

Flat View: This topic has 4 replies on 1 page
Topic: hashcode() Previous Topic   Next Topic Topic: Language Translations

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use