wood burning stoves 2.0*
The moose likes Servlets and the fly likes Writing to a file on the server whose URL is given Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Writing to a file on the server whose URL is given" Watch "Writing to a file on the server whose URL is given" New topic
Author

Writing to a file on the server whose URL is given

Vinitra Ramji
Greenhorn

Joined: Jul 19, 2011
Posts: 10

Any idea how to write/edit/modify a file that is on the server and I have the URL to that file?
Thakur Sachin Singh
Ranch Hand

Joined: Jun 15, 2010
Posts: 232

First of all you have access right or not, this matter when you write the file.


SCJP 6- 91%, IBM DB2, IBM RAD Certified
Vinitra Ramji
Greenhorn

Joined: Jul 19, 2011
Posts: 10

Thakur Sachin Singh wrote:First of all you have access right or not, this matter when you write the file.

I have the permission to write. But how do I go about it?
Abhay Agarwal
Ranch Hand

Joined: Feb 29, 2008
Posts: 1212
    
    1

I think you can create a File object using its URI constructor.Then you can use File object's method to modify that file.


Oracle Java Web Service Developer (1z0-897), Oracle certified Java 7 Programmer, SCJA 1.0, SCJP 5.0, SCWCD 5.0, Oracle SQL Fundamentals I, CIW Certified Ecommerce specialist
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18911
    
    8

No, sorry, a File object refers to a file on the local system. So that's completely incorrect.

To Vinitra: you didn't say what kind of URL you had. You can't update a file via an HTTP URL. If it were an FTP URL, you probably could.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61661
    
  67

Or perhaps it's not HTTP but WebDAV you seek.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Vinitra Ramji
Greenhorn

Joined: Jul 19, 2011
Posts: 10

It is a http URL.. Isnt there any way by which it can be done? It is located on a remote server and has to be accessed using http.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61661
    
  67

OK, so it seems you need to write some servlets to do what you want to do with the files.
Vinitra Ramji
Greenhorn

Joined: Jul 19, 2011
Posts: 10

Bear Bibeault wrote:OK, so it seems you need to write some servlets to do what you want to do with the files.


How am I supposed to go about this? I want to know the methods/objects to use.
Vinitra Ramji
Greenhorn

Joined: Jul 19, 2011
Posts: 10

I am able to read the contents of the file, given the URL but modifying the contents and writing it back to the url is the problem!
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42648
    
  65
Vinitra Ramji wrote:How am I supposed to go about this? I want to know the methods/objects to use.

Do you know how to write servlets in general? Do you know how to use the java.io package to manipulate/write the file in the way that you need? If the answer to both is "yes", can you combine both? If the answer is "no" to either of these, I'd start by learning that particular skill.

The servlet would, of course, have to run on the remote server - do you have control over that server, so that you can run servlets there?


Ping & DNS - my free Android networking tools app
Vinitra Ramji
Greenhorn

Joined: Jul 19, 2011
Posts: 10

Ulf Dittmer wrote:
Vinitra Ramji wrote:How am I supposed to go about this? I want to know the methods/objects to use.

Do you know how to write servlets in general? Do you know how to use the java.io package to manipulate/write the file in the way that you need? If the answer to both is "yes", can you combine both? If the answer is "no" to either of these, I'd start by learning that particular skill.

The servlet would, of course, have to run on the remote server - do you have control over that server, so that you can run servlets there?


I know to write servlets in general and I also know to use java.io package but combining the both I am just able to read from the file on the remote server; not able to write.

And about the server you are asking about, I have control over that server to some extent. Like I can move around the files on the server etc.
Vinitra Ramji
Greenhorn

Joined: Jul 19, 2011
Posts: 10

Paul Clapham wrote:No, sorry, a File object refers to a file on the local system. So that's completely incorrect.

To Vinitra: you didn't say what kind of URL you had. You can't update a file via an HTTP URL. If it were an FTP URL, you probably could.


How would I go about it if I had a FTP URL?

PS: I'm completely new to FTP
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42648
    
  65
Apache Commons Net is a good FTP client library.
Vinitra Ramji
Greenhorn

Joined: Jul 19, 2011
Posts: 10

Ulf Dittmer wrote:Apache Commons Net is a good FTP client library.

Thank you! I'll look through it and get back to you, if I dont find any solution!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Writing to a file on the server whose URL is given