[java] Writing to a file at a URL help

Started by
6 comments, last by Swattkidd 17 years ago
Ok i am creating a chat type of program that reads info from a file and posts it, but the problem i am haveing is being able to write to the file. The file is located in my site so i can read from it by reading from a URL but im not sure how to write to the URL, like send what the person writes in the chat box to the file when they push enter...
Advertisement
How are you trying to write to the file? What APIs are you using?

Are you using Winsock?
No im trying to write to it the way i read from it, by makeing a URL and then opening a connection with it, but im not very clear on that, right now im asking how i could do that. I dont want to make it a networked chat program yet. I just want it so that a person opens it up and it displays what the last person wrote (because it displays whats in the txt doc) and then they can type, push send, and now when another person opens it, they can see what that person wrote (because its stored in the txt doc)
Writing to the file that is on the server side should be the responsibility of an (web) application residing on that server. If you want to write to a file from remote code, you have to require the necessary permissions in a .policy file, and that can be a pain to configure and make work. I suggest you write a Servlet or something that deals with the writing, and let it receive as parameters what needs to be written on the file. Delegate different responsibilities to different classes in your architecture, making your system as 'loose coupled' as possible.
a.k.a javabeats at yahoo.ca
If you were to connect to the server via ftp and modify the file. The client would also need to have the username + password data. Thus, for security reasons would be a very bad idea. Simple decompiling of your application would reveal everything since, java is so easy to decompile anyone could do it.

Connect to a server, servlet, use a post() or get() statement for PHP to handle. and let the server deal with the modifying of the file.
Ok thanks guys, all in all ive realized my simple way of getting around networking was not so simple, so i decided to learn networking :) thanks for the advice and help!
Hi

I got the same problem, did you get any solutaion, if yes, could you please post it on this forum. I have need to do the same thing.

Regards
Lucky
No man i havent found a solution, im just learning normal networking instead..but you might be able to write to a file using servlets ;)

This topic is closed to new replies.

Advertisement