java - Why can't I delete the XML file I created? -


my first question speed of stax writer. have problem: can't delete xml file created, delete();

it still being used somehow. have tried delete manually not.
@ , of file creation call method close() streamwriter.

i trying delete file right after method done, in file. like: startstopwath;createxml(); stopstopwatch; file.delete() have add more there?

here code:

import java.io.*; import java.util.*; import javax.xml.stream.*; import org.springframework.util.stopwatch;  public class staxvytvor {      public static string subor = "test.xml";      public static void main(string[] args) {         int num =600000;         try {             string encoding = "utf-8";             xmloutputfactory f = xmloutputfactory.newinstance();             xmlstreamwriter w = f.createxmlstreamwriter(new bufferedoutputstream(newfileoutputstream(subor)), "utf-8");             w.writestartdocument(encoding, "1.0");             w.writecharacters("\r\n");             w.writestartelement("noviny");                     (int = 1;  <= num;  i++) {                 w.writecharacters("\r\n  ");                 w.writestartelement("author");                 w.writecharacters("\r\n  ");                 w.writestartelement("id");                  string id = integer.tostring(i);                 w.writecharacters(id);                 w.writeendelement();                 w.writecharacters("\r\n  ");                 w.writestartelement("meno");                 w.writecharacters("autor"+i);                 w.writeendelement();                 w.writecharacters("\r\n  ");                 w.writestartelement("email");                 w.writecharacters("author"+i+"@email.com");                 w.writeendelement();                 w.writecharacters("\r\n  ");                 w.writestartelement("phone");                 w.writeattribute("type", "pevna");                 w.writecharacters("+4219");                 w.writeendelement();                 w.writecharacters("\r\n  ");                 w.writestartelement("plat");                 w.writecharacters("5000");                 w.writeendelement();                 w.writecharacters("\r\n  ");                         w.writeendelement();                  w.writecharacters("\r\n");             }             w.writecharacters("\r\n");             w.writeendelement();                     w.writecharacters("\r\n");             w.writeenddocument();             w.close();               system.out.println("success");          }         catch (exception e) {             e.printstacktrace();         }     } } 

i trying delete here:

domvytvor.main(args); try {      file file = new file ("stax.xml");      if(file.delete() && file1.delete() ){         system.out.println(file.getname() + " deleted!");     }     else{         system.out.println("delete operation failed.");     } } catch(exception e) {     e.printstacktrace(); } 

closing xmlstreamwriter not close underlying output stream.

see:

http://docs.oracle.com/javaee/5/api/javax/xml/stream/xmlstreamwriter.html#close()


Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

How to call a javascript function after the page loads with a chrome extension? -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -