Thank you for adhering to the policy. I appreciate your input in this forum very much. I am glad that you understand that we are just trying to maintain a professional atmosphere.
You might have missed the section in our naming policy page that said:
If you are currently using an account that uses an inappropriate alias, please create a new account that follows the rules. The software we use here is not capable of changing the name on an existing account and we have unlimited account slots.
I want to maintain a professional exchange on JavaRanch so that corporate america won't feel embarassed to find employees spending time here.
Unfortunately, as it says, it is not possible to change the user name. To continue posting here, you must re-register with a new name. Here is the link where you can do that: http://www.javaranch.com/cgi-bin/ubb/Ultimate.cgi?action=agree
I hope that you will complete this process so that we can get on to answering your questions and getting your valuable input on the questions of other ranchers.
It is a little difficult to trouble-shoot without seeing your code. How are you attempting to write this file on the server? One option would be to use sockets. There is a very good and simple example of how to implement sockets here: http://java.sun.com/docs/books/tutorial/networking/sockets/index.html
The section titled "Writing a Client/Server Pair" might work for you here.
The section titled "Using a Server to Work Around Security Restrictions", here: http://java.sun.com/docs/books/tutorial/applet/practical/workaround.html
might also help.
If this is not what you had in mind or if I have misunderstood your goal, please post again so that we can find a better solution.
String fileName = "data/test1.dat";
URL url = new URL(myApplet.getDocumentBase(), fileName);
File datFile = new File(url.getFile());
BufferedReader in = new BufferedReader(new FileReader(datFile));
String line = in.readLine();
I put in the println for debugging. On the java console it does show me a valid directory file path. However, I am not getting any data for my app and I don't get any security violations.
I guess the bottom line is can an applet open a file from a root webserver directory just as opening one on the file system. Any help you can give is greatly appreciated.
String fileName = "data/temp.dat";
URL url = new URL(calApplet.getDocumentBase(), fileName);
URLConnection connection = url.openConnection();
out = new PrintWriter(connection.getOutputStream());
out.write("This is a test",0, outString.length());
Before this when I had the Applet as a file in the dirctory I was using FileWriter and I didn't have any problems. The FileWriter doesn't seem to work when going from a webserver. I would appreciate any help.
To write to the file, you'll need to have a program running on the server which will receive the data from the client, and then write to the file using FileWriter etc.
One way is to have a simple java server program (say FileWriterServer), running on some port (say 5000), on the same host as your webserver. This program would listen by opening a ServerSocket. The applet will then open a socket connection with the FileWriterServer. Then through the socket, the applet will send the data. The FileWriterServer, will receive the data through the socket, and using the FileWriter, write to the file.
The FileWriterServer could also be implemented as RMI Server exposing a remote method writeFile(String, fileURL). The RMI Server would implement the writeFile method, using a FileWriter to write the String parameter to the File pointed by the URL. The applet would then need to call writeFile() method, whenever it needs to write to the file.
Another way to do it is through a servlet. Make a servlet, implementing its doPost method, to receive Post data and then using FileWriter, write that data to the file. This servlet can be called through the URLConnection.
Waiting to hear your comments.
Basically I don't know why I have to implement a whole other server app to just write a basic text file. Seems like Sun shoud provide some functionality for this. Please tell me your thoughts
A program running on one host cannot directly access the file-system/local resources of another host. Remember that even for reading a file from the remote host you are using a server (eg. web server). You can request the web-server to serve up the contents of a (static) resource or to initiate a program (CGI/Servlet) and then serve up the response of that program but a web-server is not designed to directly write to a file. So use the web-server to call a servlet to write to the file. Or have a server (on a different port from the web-server), to write to the file. Programming a server/servlet is almost a trivial task in Java. It can be done in a few lines of code.