开发者

How can i handle this Error in FileWriter?

开发者 https://www.devze.com 2022-12-19 23:05 出处:网络
I have a problem please guide me :) I write this method : public void createTempFile() throws Exception{

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.deleteOnExi开发者_开发问答t();
                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 ...


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();


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

0

精彩评论

暂无评论...
验证码 换一张
取 消