|
|
Re: how to use beans for file copy on another machine on LAN?
|
Posted: Sep 1, 2005 7:42 AM
|
|
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
|
|