1

If i pass this fil Object to the Server can i create the same file there??

File fil=new File("D://Resume.doc");

4 Answers 4

1

File object just holds a reference to physical file in your FS. You can't regenerate if you simply pass it to server

Sign up to request clarification or add additional context in comments.

2 Comments

so what shoud i pass over there??
Basically you need to read bytes of file and send from sender and at receiver end do the exact reverse, here you can find a basic example as reference
1

The File instance names a file, and is distinct from the actual file storage itself.

If you serialize this to the server, the server may be able to create the file locally, although this has no relation to the fact that it was serialized from the client, and will behave exactly as if you called new File('D://resume.doc') on the server.

Either way, it will be a local copy of the file on the server that you open, not the copy on the client.

To open a client's file on the server, you will either need to use a networked file system (e.g. Windows Shares/Samba) or you have the client send the contents of the file to the server. Commons FileUpload, which provides robust file upload functionality for web applications, could be useful here.

Comments

1

can i create the same file there??

No, you need to pass on the bytes representing the file to the server (in your case a MS Word file) for the server to re-create the file there i.e. similar to uploading a file. The specifics depend on what kind of server you have and which protocol you are using.

Comments

0

As long as its not saved on the server yes, otherwise you will get a file name conflict

3 Comments

I guess you need to send you file to the server too , check this link for file transfer using sockets in java: rgagnon.com/javadetails/java-0542.html
i checked that bt i also have to pass other information also.. like many strings and all..
So save the strings you need to a file and send another file. or you save the file in a new object which contains the file and the data, save this to a binary file and send the binary file, once the file is on the server you will need to cast it and extract the data out of the object including your original file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.