Hello Daniweb!
I have a .txt file on a URL and I'm able to read its contents and display them however and wherever I want in my applet without any issues with this simple code:
URL url = new URL("http://blabla.com/something.txt");
BufferedReader input = new BufferedReader(new InputStreamReader(url.openStream()));
String str;
Boolean continueLoop = true;
while ((str = input.readLine()) != null && continueLoop) {
String[] fileContents = str.split(" ");
... // format and organize the array for display
...
However my issue is with writing (appending to existing content) to this file.
I've got:
URL url = new URL("http://blabla.com/something.txt");
URLConnection connection = url.openConnection();
connection.setDoOutput(true);
OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream());
out.write("Good morning Starshine! The earth says HELLOOO!!");
out.close();
but that's not working. I have a complicated solution working, which is to download the file, apply the changes, then re-upload to the server again, but there's gotta be a better, faster and more efficient way to do this. The file does have read, write and execute permissions.
Help please!