Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Appending to a txt file on the internet  RSS feed

 
Matti Poro
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to append to a txt file that is on my homepage. The file has been chmodded to 777. This is what I've got so far:

import java.net.*;
import java.io.*;

class test {
public static void main(String[] args) throws Exception {
URL url = new URL("http://www.myhomepage.com/test.txt");
URLConnection con = url.openConnection();
con.setDoOutput(true);
OutputStream out = con.getOutputStream();
out.write('a');
out.close();
}
}

The txt file is not modified.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't modify a static web resource like a text file in this manner. You can use the URL class to issue HTTP GET and POST requests, but for them to change anything on the server, there would need to be an active server component (like a servlet).

WebDAV is a protocol that is "kind of, sort of" a file system that works over HTTP. You would need to install it especially on your web server, though. Tomcat ships with a WebDAV implementation.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!