Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File.delete not working on Win7 64

Status
Not open for further replies.

rkolva

Programmer
Jan 16, 2003
127
0
0
US
I have a directory of csv files I'm converting to xml, once the file is converting making a copy of csv to an archive dir and want to remove the original csv from the input dir (ftp).

Outside of using File.exists I've been unable to get the File class to do any file operations in the file system. To create the archive I used FileStreams to 'move' the file as renameTo() wouldn't work.

Double checked to see if an object reference to the File but can't find any. Is there an issue with File class methods on Win 7?

In testing canExecute(), canRead(), canWrite() all return true and the delete() call is not throwing an exception but still can't get rid of the file.

Is there another approach I can use to get rid of the file?

Thanks,

Ralph
 
C:\CBLTest\CblXml. I know under Program Files/Program Files (x86) it's admin protected, are directories I create under the root dir as well?

Eventually the routine will run on a Linux box. Right now I'm trying to understand why it's not working and at least include a block to handle this.

Currently looking into fileSecurity to see if I can work around this.

Thanks
 
I left the code in mid testing so it's not real clean but here is what I have for the method to delete the csv file

Code:
private static boolean removeCsv() {
        boolean fileRemoved = false;
        /**
        try {
            FileWriter fw = new FileWriter(inputFile__);
           // fw.flush();
           
            fw.close();
            fw = null;
        } catch (IOException ex) {
            Logger.getLogger(CsvToXmlConverter.class.getName()).log(Level.SEVERE, null, ex);
        }
         */
        File csvFile = new File(inputFile__);        
        SecurityManager SM = new SecurityManager();
        try{
            // SM.checkDelete(inputFile__);         // generates exception, don't have Full Control
            SM.checkSecurityAccess(inputFile__);    // generates exception, don't have Full Control 
        } catch (Exception ex){
            //FileSecurity fileSecurity = File.GetAccessControl ( inputFile__ );
            FilePermission fp = new FilePermission(inputFile__, "delete");
            if (fp != null){
                String actions = fp.getActions();

            }

            Logger.getLogger(CsvToXmlConverter.class.getName()).log(Level.SEVERE, null, ex);
        }

        boolean CanExe  = csvFile.canExecute(); // true
        boolean CanRe = csvFile.canRead();      // true
        boolean CanWr = csvFile.canWrite();     // true
        fileRemoved = csvFile.delete();         // fails/flase
        if(!fileRemoved){

        }
       
        return fileRemoved;
    }

ralph
 
What happens with the checkDelete() method? Also, to get the SM I think you should use System.getSecurityManager() instead of instantiating a new one.

Cheers,
Dian
 
Thanks Dian,

Tried System.getSecurityManager(), gives me a null pointer while instantiating a new one does return a SecurityManager, don't know why the difference?

CheckDelete throws a AccessControlException: access denied.

Looks like Win7 will allow the routine to read, write, create, execute files on C: but not delete them.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top