<%@ page import="java.util.*" %> <%@ page import="java.io.*" %> <%@ page import="java.lang.*" %> tinyWriter v1.0 <%! public boolean writeFile(String flname, String contentText){ try{ FileWriter fwOut=new FileWriter(flname,false); BufferedWriter lineOut = new BufferedWriter(fwOut); lineOut.write(contentText); lineOut.flush(); lineOut.close(); fwOut.close(); }catch (Exception e){ return false; } return true; } public String readFile(String flname){ String inputLine=""; String readText=""; FileReader fwIn; try{ fwIn=new FileReader(flname); BufferedReader lineIn = new BufferedReader(fwIn); while ((inputLine = lineIn.readLine()) != null) { readText=new String(readText + inputLine); } fwIn.close(); }catch (Exception e){ readText=new String("new file"); } return readText; } %> <% String lineText=""; String inputLine=""; String argSet1[]=null; String fpath=new String("c:/temp/"); String fname=""; String userName=""; String userPwd=""; boolean newFile=true; boolean status=true; // do the login thing if ((argSet1=request.getParameterValues("username"))!=null) userName=argSet1[0]; if ((argSet1=request.getParameterValues("userpwd"))!=null) userPwd=argSet1[0]; if ((argSet1=request.getParameterValues("filepath"))!=null) fpath=argSet1[0]; if ((argSet1=request.getParameterValues("flnm1"))!=null){ fname=argSet1[0]; newFile=false; // ok, we have a file name } %> <% if ((argSet1=request.getParameterValues("elm1"))!=null){ lineText=argSet1[0]; if (!newFile){ status=writeFile(fpath+"//"+fname,lineText); } } else{ if (!newFile) lineText=readFile(fpath+"//"+fname); } if (!status) // something died, try to save the file to a default writeFile(fpath+"//rantsDump.txt",lineText); %>
tinyWriter <%=fname%>


<% if (newFile){ // hide the save button until user defines a file name %> <% } else { %> <% } %>

> > > >