views:

42

answers:

2

Hi Guys

I have a problem please guide me :)

I write this method :

public void createTempFile() throws Exception{
                //CHTYPE & FINAL are Vector 
                File file = File.createTempFile("Temp", ".txt", new File(System.getProperty("user.dir")));
                file.deleteOnExit();
                FileWriter fw = new java.io.FileWriter(file);
                for (String aContent : CHTYPE) fw.write(aContent + "\n");
                fw.close();
                traffic tr = new traffic(file);
                for (int i = 0; i < tr.result.size(); i++)
                    FINAL.add(tr.result.get(i));
                getEHRACT(); //Calculating in some integer & some Double
        }

when I run this method in IDE(Intellij Idea) it's correctly run and a temp file delete after this line

file.deleteOnExit(); 

but when I make my application as a jar file this file doesn't delete till I exit my application and some calculations don't execute :( why?

Please help me thanks ...

+3  A: 

Your file doesn't get deleted until you application exits because... that's what you told it to do. If you want to delete a file right away, then you use its delete method.

file.delete();
Jonathan Feinberg
thanks dear Jonathan Feinberg my problem fixed ...
Mike Redford
A: 

The "OnExit" part means "on exit from the VM", not "on exit from my function" or whatever

Pointy