下面是这段程序,它生成一个log.txt文件,如果用java生成就能删除,但是如果用jsp生成,有时候能删除有时候不能。不能删除的时候,给出的错误信息是:文件正在被使用,constraint  不能被violate.  另外这段程序写在了好几个方法里成生不同的logfile。  
 
 
public  static  void  generatefile(String  path,int  count)  throws  Exception{  
                   flag=0;      
                   File  f  =new  File(path);  
                   File[]  ff=f.listFiles();  
                   for(int  ii=0;ii<ff.length;ii++){  
                   String  name=ff[ii].getName();  
          if  (ff[ii].isFile()  &&  name.startsWith("log")  &&  name.endsWith(".txt")){  
                   flag=1;  
                   }  
                   }  
                         
                   if(flag==0)  {  
                      String  probuffer;  
                      probuffer="here  is  the  logfile";  
                      for  (int  j=1;j<=count;j++){  
                        probuffer=probuffer+"count"+j;  
                        probuffer=probuffer+".txt\r\n";  
                      }  
                       
                    OutputStream  outprof1=new  FileOutputStream(path+"log"+".txt");  
                    outprof1.close();  
                    FileWriter  fwprof  =  new  FileWriter(path+"log"+".txt");    
                    PrintWriter  outprof=new  PrintWriter(fwprof);  
                    outprof.write(probuffer);  
                    outprof.println();    
                    outprof.flush();    
                    outprof.close();  
             
                    }  
 
                   else  {  
                    String[]  prof=new  String[50];  
                    String  probuffer="";  
                    String  s=null;  
                    int  fileposition1;  
                    int  fileposition2;  
                    int  account=0;  
                    fileposition1=0;  
                    fileposition2=0;  
                    for(int  i=0;i<50;i++)  
                      prof[i]="";  
                           
                   FileReader  fr=new  FileReader(path+"log.txt");  
                   BufferedReader  fff=new  BufferedReader(fr);  
                   while((s=fff.readLine())!=null){  
                       if(!s.equals("")){  
                         prof[account]=s.trim();  
                         account=account+1;  
                       }  
                    }  
                         
                    for(int  i=0;i<account;i++)    {  
                      if(prof[i].equals("<files>"))  
                         fileposition1=i;  
                      if(prof[i].equals("</files>"))  
                         fileposition2=i;  
                     }  
                         
                     for(int  i=0;i<fileposition1+1;i++)  
                       probuffer=probuffer+prof[i]+"\r\n";  
                     for(int  j=1;j<=count;j++){  
                        probuffer=probuffer+"count"+j;  
                        probuffer=probuffer+".txt\r\n";  
                      }    
                           
                     for(int  i=fileposition2;i<50;i++)  
                        probuffer=probuffer+prof[i]+"\r\n";  
                     
                     OutputStream  outprof1=new  FileOutputStream(path+"log"+".txt");  
                     outprof1.close();  
                     FileWriter  fwprof  =  new  FileWriter(path+"log"+".txt");    
                     PrintWriter  outprof=new  PrintWriter(fwprof);  
                     outprof.write(probuffer);  
                     outprof.println();    
                     outprof.flush();    
                     outprof.close();      
 
                 
               }  
                       
 
           }  
 
 
written  by  Ji  Li