I'm having real trouble generating a text file per 'operation' to store operation specific information, no matter what approach I take, I can't create a text file on the web server, let alone store information within it, the first example is ideally what I'd like (create and store per operation)
Note - I'm trying to do this in a servlet currently for testing purposes. Help much appreciated.
try {
FileWriter fstream = new FileWriter("out.txt");
BufferedWriter out = new BufferedWriter(fstream);
out.write("test");
out.close();
} catch (Exception ex) {
System.out.println(ex);
}
Different Approach
try {
URL url;
URLConnection urlConn;
DataOutputStream dos;
DataInputStream dis;
url = new URL("http://localhost:8080/" + request.getContextPath() + "/tmp/myfile.txt");
System.out.println(url);
urlConn = url.openConnection();
urlConn.setDoInput(true);
urlConn.setDoOutput(true);
urlConn.setUseCaches(false);
urlConn.setRequestProperty ("Content-Type", "text/plain");
dos = new DataOutputStream (urlConn.getOutputStream());
dos.writeUTF("test");
dos.flush();
dos.close();
//to test
dis = new DataInputStream(urlConn.getInputStream());
String s = dis.readLine();
System.out.println(s);
dis.close();
} catch(Exception ex) {
System.out.println(ex);
}