Oracle删除指定目录文件

由于微软的图表控件Chart生成的临时图片保存在C:\TempImageFiles,所以需要进行定时删除。操作步骤如下。

Sys用户登录

execute dbms_java.grant_permission('TXGS','SYS:java.io.FilePermission','C:\TempImageFiles','read');

execute dbms_java.grant_permission('TXGS','SYS:java.io.FilePermission','C:\TempImageFiles\*','delete,read');

 

Java源:

create or replace and compile java source named deletefile as

import java.awt1.*;

import java.io.*;

import java.io.File;

import java.lang.String;

 

public class DELETEFILE

{

   public static String delAllFile()

   {

       String   path="C:\\TempImageFiles";

        File file = new File(path);

       if (!file.exists()) {return ""; }

       if (!file.isDirectory()) {return ""; }

       String[] tempList = file.list();

       File temp = null;

       for (int i = 0; i < tempList.length; i++)

       {

           if (path.endsWith(File.separator))

           {

               temp = new File(path + tempList[i]);

           }

           else

           {

               temp = new File(path + File.separator + tempList[i]);

           }

           if (temp.isFile())

           {

               temp.delete();

           }

           if (temp.isDirectory())

           {

               java.io.File myDelFile = new java.io.File(path+"\\"+ tempList[i]);

               myDelFile.delete();

           }

         }

        return( "0 ");

    }              

 

}

 

存储过程:

create or replace procedure RunDx as language java name   'DELETEFILE.delAllFile()';

 

 

posted on 2010-07-02 08:39  松原蔡晓冬  阅读(2614)  评论(2编辑  收藏  举报

导航