Results 1 to 4 of 4
- 04-01-2012, 02:17 AM #1
Member
- Join Date
- Apr 2012
- Posts
- 4
- Rep Power
- 0
- 04-01-2012, 03:10 AM #2
Re: Help on sending a directory file over a socket
One way would be to define your own protocol to describe the directory structure.
There might be a way to describe the structure using classes in anther class and then serialize and send the containing class.If you don't understand my response, don't ignore it, ask a question.
- 05-20-2012, 11:20 PM #3
Member
- Join Date
- Apr 2012
- Posts
- 4
- Rep Power
- 0
Re: Help on sending a directory file over a socket
Thanks a lot Norm.
I have used the follwing two methods that helped me to construct DefaultMutableTreeNode and send it over a socket as an object. The returend object is DefaultMutableTreeNode
DefaultMutableTreeNode CreateTree ()
{
String myfile = ("C:\\");
Fullpath =myfile+"TmpDir";
File file=new File(Fullpath);
boolean exists = file.exists();
if (!exists)
{
// It returns false if File or directory does not exist
try{
// Create one directory
boolean success = (new File(Fullpath)).mkdir();
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
// Create a local user tree
root = new DefaultMutableTreeNode(username.getText(), true);
getList(root,new File(Fullpath));
return root;
}
public void getList(DefaultMutableTreeNode node, File f) {
if(!f.isDirectory()) {
if (f.getName().endsWith("")) {
DefaultMutableTreeNode child = new DefaultMutableTreeNode(f);
node.add(child);
}// end if
}//end if
else {
DefaultMutableTreeNode child = new DefaultMutableTreeNode(f);
node.add(child);
File fList[] = f.listFiles();
for(int i = 0; i < fList.length; i++)
getList(child, fList[i]);
}
}//end get list
- 05-21-2012, 05:44 AM #4
Re: Help on sending a directory file over a socket
Why do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
Sending a JPEG file over a tcp socket and saving it
By busdude in forum New To JavaReplies: 0Last Post: 12-02-2010, 09:31 PM -
Sending and splitting an image file over tcp socket.
By busdude in forum Advanced JavaReplies: 1Last Post: 12-02-2010, 10:03 AM -
Problems with sending zip file using Socket
By morita in forum NetworkingReplies: 0Last Post: 05-14-2010, 06:41 PM -
Sending a file through socket
By sureshkumarcs88 in forum NetworkingReplies: 2Last Post: 03-14-2009, 07:32 AM -
Sending a .Doc file from client to a server through socket
By amita_k29 in forum NetworkingReplies: 1Last Post: 02-10-2009, 09:16 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks