Harinder
Harinder

Reputation: 11944

Create file using File object?

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

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

Upvotes: 1

Views: 674

Answers (4)

Sanjay T. Sharma
Sanjay T. Sharma

Reputation: 23208

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.

Upvotes: 1

mdma
mdma

Reputation: 57707

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.

Upvotes: 1

CloudyMarble
CloudyMarble

Reputation: 37566

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

Upvotes: 0

Jigar Joshi
Jigar Joshi

Reputation: 240860

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

Upvotes: 1

Related Questions