hi all, i have a servlet which writes something to a text file(say filename.txt).i want that whenever the servlet is executed again then it should delete the already existing filename.txt and create a new one.how can this be done..please help..its urgent..(i tried File.delete() but it throws some weird exception and doesnt let me delete the file)... PS-can file deletion be done from an applet? thanks a ton regards karan
hi karan, I have faced a similar problem .you can not delete a file which is refrenced by any server.even as aruna suggested is not possible i have tried that.what i did is that i created a new file object with the same file name.so now the file is empty .so any text is return from the scratch.
hi aruna and srinivas, i worte the following code for deleting the file in my servlet as aruna said and it gave me the following exception in my applet. public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html");
File name = new File("/","node.txt"); if(name.exists() && name.isFile()) { name .delete(); }
FileWriter fw = new FileWriter("dir path" + "node.txt", true); BufferedWriter bw = new BufferedWriter(fw);
FileWriter fw1 = new FileWriter("dir path" + "link.txt", true); BufferedWriter bw1 = new BufferedWriter(fw1);
FileWriter fw2 = new FileWriter("dir path" + "incident.txt", true); BufferedWriter bw2 = new BufferedWriter(fw2); now i write the 3 files } this is the exception java.lang.NumberFormatException: multiple points at java.lang.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1036) at java.lang.Double.valueOf(Double.java:168) at Simple.drawPoint_database(Simple.java:461) at Simple.paint(Simple.java:715) at javax.swing.JApplet.update(JApplet.java:133) at sun.awt.RepaintArea.update(RepaintArea.java:337) at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:197) at java.awt.Component.dispatchEventImpl(Component.java:2665) at java.awt.Container.dispatchEventImpl(Container.java:1213) at java.awt.Component.dispatchEvent(Component.java:2499) at java.awt.EventQueue.dispatchEvent(EventQueue.java:319) at java.awt.EventDispatchThread.pumpOneEvent(EventDispatchThread.java:103) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93) at java.awt.EventDispatchThread.run(EventDispatchThread.java:84) simu java.lang.NumberFormatException: multiple points at java.lang.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1036) at java.lang.Double.valueOf(Double.java:168) at Simple.drawlink_database(Simple.java:536) at Simple.paint(Simple.java:731) at javax.swing.JApplet.update(JApplet.java:133) at sun.awt.RepaintArea.update(RepaintArea.java:337) at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:197) at java.awt.Component.dispatchEventImpl(Component.java:2665) at java.awt.Container.dispatchEventImpl(Container.java:1213) at java.awt.Component.dispatchEvent(Component.java:2499) at java.awt.EventQueue.dispatchEvent(EventQueue.java:319) at java.awt.EventDispatchThread.pumpOneEvent(EventDispatchThread.java:103) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93) at java.awt.EventDispatchThread.run(EventDispatchThread.java:84) basically wheni execute my applet then it communicates with the servlet which in turn generates 3 output files which are then read byu the applet.but i want them to be new files when the applet reads them.but as i menitioned above.it is not working.
hey srinivas, can u take a look at my code attached above and provide me with a code of what u did to take care of the problem..please..it would be a great help,really.. regards karan
Post by:autobot
I'm doing laundry! Look how clean this tiny ad is:
a bit of art, as a gift, that will fit in a stocking