Why can't I delete the file?

What I want to do is: After user download the file from web, the application will delete the file automatically on ther server. However, the delete function cannot work which it prompts the java.lang.Exception, I suspent it is the download process hold the file, how can I solve it?
DownloadReport(request, response, reportFile);
Utility.deleteFile(reportFile);
     public void DownloadReport(HttpServletRequest request,
               HttpServletResponse response, String reportFile) throws Exception {
          File fFile = new File(reportFile);
          String stFileName = fFile.getName();
          response.setContentType("application/vnd.ms-excel");
          response.setHeader("Content-Disposition", "attachment;filename=\""
                    + stFileName + "\"");
          // System.out.println("Henry "+getServletContext());
          InputStream isStream = null;
          try {
               PrintWriter out = response.getWriter();
               isStream = new FileInputStream(fFile);
               int i;
               while ((i = isStream.read()) != -1) {
                    out.write(i);
               isStream.close();
               out.close();
          } catch (Exception ioeException) {
               log.error("Download report error", ioeException);
               ioeException.printStackTrace();
               throw new ServletException("Download report error", ioeException);
     public static void deleteFile(String path) {
          boolean deleted = false;
          try {
               File delefile = new File(path);
               if (delefile.exists())
                    deleted = delefile.delete();
               if (deleted == false)
                    throw new Exception("File could not be deleted " + path);
          } catch (Exception e) {
               e.printStackTrace();
     }

Hi, my application is using POI API generating the Excel report, after genration, the report will be stored on the server, and then user download the report to their local machine throught web and then I delete the report on the server. I don't quitely understand what you mean, could you kindly explain to me detailly:p. Btw, I have tried to print out the exception, but it only shows "java.lang.Exception: File could not be deleted " which is so limited. If I comment the DownReport function, the file could be deleted successfully. But if it happens after the download action, it is failed.

Similar Messages

  • Why can't I delete mp3 files from my Trash?  They are not locked.

    Why can't I delete mp3 files from my Trash? They are not locked.  I compressed them into a zip file and then couldn't delete that file either.  I've restored them and tried deleting again but no luck.  Can anybody please help?  iOS 10.8.5

    You can't empty the Trash or move a file to the Trash
    Visit The XLab FAQs and read the FAQ on solving Trash issues. You can also try using Trash It! 5.1 to fix the problem. Or you can try this:
    Open the Terminal in the Utilities folder and paste the following at the prompt:
         sudo rm -Rf ~/.Trash/*
    Press RETURN. Enter your admin password when prompted. It will not echo to the screen. Press RETURN again.

  • I keep getting an error stating that my disk is full in syslog. The file is empty and I want to stop it from logging data. Can I just delete the file?

    Can I just delete the syslog file?

    Hello,
    Yes, you can delete the file. A new file in Syslog directory is started each time that LabVIEW and the Tag Engine is started. You can either manually delete old files or write a simple VI to automatically delete files that are older than a certain number of days.
    As an alternative, you can save these files into another folder, just to free up syslog directory space, and still have these history files for later use.
    Zvezdana S.
    National Instruments

  • Why can't I delete certain files from my Time Capsule?

    I don't have my Time Capsule set up to back up every hour or so.  It's set up so that I can manually drag & drop files into it.  I've been trying to free up space by deleting some movie files that don't need anymore.  They appear to be just .avi format but I haven't been paying close enough attention to see if any other formats won't delete.  What prevents certain files from being deleted from the Time Capsule?                                                                                

    Dogs 'n Front wrote:
    Under the DISK/File Sharing tab in Airport Utility, I have the File Sharing box checked.
    What about the setting for "Secure Shared Disks"?
    Dogs 'n Front wrote:
    I didn't check EVERY single video and their info but a few I checked had the same permissions:  "Everyone" and "Read & Write"
    I only asked about each folder down the hierarchy to and including one video you can't delete.
    If you copy a new file into each of the higher-level folders down to and including the "MOVIES" folder, can you then delete that new file?
    If you're willing to use a command in a Terminal session, I can tell you how to determine what process has a file open.
    I'll be offline for the next few hours, so I won't be able to reply as quickly as I've been for the last several exchanges.

  • I can't open a pdf file in a browser window. I have to save it before I can open it. Why can't I open the file without first having to save it?

    Anytime that I click on a pdf file in a browser window, the file will not open automatically. I am forced to save it on my computer first and then access the file. When I click on it after it is saved locally, it opens as it should.

    If you are not able to get Adobe Acrobat Reader to open .pdf files in the browser. Even after you check in prefs to show pdf files in the browser.
    Make this modification for all versions of Adobe Acrobat Reader that show under this key.
    -Note: Deleting the key and all subkeys for any older versions also seems to fix this problem. So if you see this key present,
    HKEY_CURRENT_USER\Software\Adobe\Acrobat Reader\7.0\Originals
    delete the 7.0 and all subkeys.
    HKEY_CURRENT_USER\Software\Adobe\Acrobat Reader\9.0\Originals
    -Right click on Originals and choose NEW DWORD Value and name it bBrowserIntegration, hit enter,
    double click on the new value and make sure the value is 1

  • In Spotlight, Why can't I see the file location?

    There has been a loss of a feature from 10.6 SL or 10.7 Lion....
    When I search for a file in Spotlight, I want to see the file location. Instead, I get the file preview. Is there a way to set a perference so I can actually "find" my file in the folder instead of just viewing it.

    You're welcome!

  • HT3775 why can i not open the file format MPEG_4(mp4) on my mac with Quick player?

    i can not open the email with file format MPEG_4(mp4) which is one of the contents on the file format listing , supporting by Quick time player but still can not be opened . !!!!!!!!! by the way my quick time player version:10.2(603.6)

    The file extension, .mp4, .wmv, .mov, etc. really has no bearing on whether it can play or not. It should, but that is not the way it works. The file type is merely a wrapper around the media content. That media content can be encoded with lots of different encoding algorithms. If it is encoded with a scheme that Quicktime doesn't understand, then it won't play in Quicktime Player.
    You might try installing the Perian plugin for Quicktime. It might have the codecs necessary to decode the media content.
    Another option is to use Video LAN's VLC. It plays a lot of things.

  • Why can't I delete some files on iDisk?

    I need to delete some sync data on the iDisk (MobileMe syncing is corrupted). But for many files I get the message: "you don't have sufficient privileges for some of the items".
    And mind you, these are NOT the core files like Backup, Documents, Web etc. which I know cannot be deleted. These are files and folders underneath these 'core folders', like Bookmarks.xml under iDisk>Library>Applications Support>Bookmarks.
    Thanks in advance for any pointers/suggestions/solutions. Cheers, Veit

    The best procedure would probably be to go to System Preferences>MobileMe>Sync, stop sync (do this on all machines), then click on the 'Advanced' button and then on 'Reset sync data'.
    Then you will need to set up all syncing again from scratch. Though I've never tried to tamper with the files you mention I wouldn't be surprised to find they were protected (as is the '_gallery' folder in Web/Sites) to stop people deleting them inadvertently.

  • HT4413 Why can't I find the files and data I transferred from time machine on my new mac?

    So I just got a new mac and I always backed up my old mac. I used the migration assistant to transferr all the stuff from my old mac to the new one. After it completed I tried  to find all my pictures, music, and documents but couldn't. Where did all my stuff go and why can't I find it? Migration Assistant said everything transferred and went ok.

    Peruse Pondini's Setup New Mac guide and seriously consider starting over. I'm a firm believer in only using the Setup Assistant and not creating a new account on first boot.

  • HT3842 I want to conserve space on my hard drive. Can I safely delete the file and redownload it later?

    How would I do this?

    euscac wrote:
    what else do you want to know?.
    This Info is a good start and was not evident in your first post...
    euscac wrote:
    ... I am using a lot of storage for ITunes TV shows and Movies. I would like to view them again later but don't want to tie up stoage in the meantime.
    See here for Moving and Using iTunes on an external Hard Drive.
    Copy your ENTIRE iTunes FOLDER to an External Drive...
    Full Details Here  >  http://support.apple.com/kb/HT1751
    Have a look at these 2 Videos...
    http://macmost.com/moving-your-itunes-library.html
    http://macmost.com/moving-your-itunes-media-to-an-external-drive.html
    To Operate iTunes from the External Drive...
    Start iTunes with the Option key held down and guide it to the new location of the library.

  • Why can't I delete songs?

    I have a problem I have an i-pad and i-pod that I share with my children and I've put on all the restrictions I feel are  appropriate, but certain songs are still in the library.  So I simply want tto delete those songs form these devices.  Why can't I delete the selected songs from these devices?  I do not have i-cloud sync turned on these devices.

    Hello Unsilenced,
    You did the first thing I would have done as well by attempting to delete the content and re download it. If you have not already, I would suggest restarting the computer and see how it looks after that. IF the issue persists then I would recommend checking for 3rd party plugins that may be interfering with this article:
    iTunes: Troubleshooting issues with third-party iTunes plug-ins
    http://support.apple.com/kb/TS3430.
    If the issue is not resolved after that, I think recreating the iTunes library would be the next best step here.
    iTunes: How to re-create your iTunes library and playlists
    http://support.apple.com/kb/HT1451
    All the best,
    Sterling

  • Why can't I delete my mail folders on my 4th gen ipad like I could on my 3 gen ipad?

    Why can't I delete the old mail messages on this 4th gen ipad. I could do it on my old 3rd gen ipad

    Hi joyceannlake1960,
    In the iPad User Guide there are a few good pages that may help get you acquainted with deleting mail messages:
    iPad User Guide for iOS 6.1
    http://manuals.info.apple.com/en_US/ipad_user_guide.pdf
    Page 44 has some good info on the layout of the buttons and what they do:
    Page 46 has instructions:
    Cheers,
    - Ari

  • I cannot download Mavericks. Every time the file download stops a message appears that says the file is damaged and cannot be used to install Mavericks. I delete the file, download again and the same message appears. What can I do?

    I cannot download Mavericks. Every time the file download stops a message appears that says the file is damaged and cannot be used to install Mavericks. I delete the file, download again and the same message appears. What can I do?

    I only have one video project that I ever published to iDisk. It didn't have any music or photo files attatched to it, just a few clips stitched together. I can play these clips right now in the Event Library (so I know the source files are on my computer), but strangely, under the Project Library, the project is not there. I'm almost certain that I didn't store the project on iDisk; I just completed the video and published it to iDisk (as a .mov file I think) for family to see. I've tried to figure out how to get iDisk to stop looking for this project to no avail.
    I don't know if others have experienced this, but if I click on any project and on the menu bar select Share --> Remove From --> Media Browser... it lists iPod, iPhone, iPad, tv, Computer and MobileMe. Why would MobileMe be an option here? This is the case for any video project I select. Didn't iLife '11 and/or OSX 10.8 remove all mention of MobileMe? I wonder if this is part of the problem too.
    Edit: I just removed every project I have from the Media Browser. Still no luck.

  • I can not delete the file!Help me please.

    I use File.delete() to delete a file,
    but it didn't work,
    why?
    OS is win2k.
    Thanks

    Hi All,
    I have been chasing down the solution to this problem in more than one thread, and, for my situation at least, I have found it.
    It was stupidity on my part... that was the problem. No, I did not carelessly fail to do a close() on the stream, or any similar thing.
    No, I stupidly used the filename when I instantiated the File object with which I was to delete the file, rather than the entire path plus filename. Consequently, to the File object, the file didn't exist (you are allowed to create File objects in Java with bogus file names). This can be tested by using the exists() method of the File instance.
    Here's some code that worked for me:
         private void deleteFiles(){
              //Your mission: delete all files in subdirectory "Output" of
              //"C:/Input/".
              File inputDirectory = new File("C:/Input/");
              String[] outputFiles;
              File outputDirectory = new File(inputDirectory.getPath() +
              "\\Output\\");
              outputFiles = outputDirectory.list();
              for(int i = 0; i < outputFiles.length; i++){
                   File aFile = new File(inputDirectory.getPath() +
                   "\\Output\\" + outputFiles);
                   aFile.delete();
    I hope that this is helpful.
    I am,
    Mike O'Connor
    (the "power user", not the professional by the same name who also participates in this forum)

  • Can I delete the files/folders in 'Apple Computer\MobileSync\Backup'?

    Hi!
    I have just tried to backup and update my iphone to iOS 5.1. The backup seems to have worked but when it came to restoring the iphone, I think the hard disk ran out of space and so it failed. I saw this and so I freed up around 3Gb of disk space and I tried it again. It again failed. Again I noticed that there was no space left on the hard disk. I assumed that to continue the restore it probably won't need that much more space (as it had already done most of the work) so I freed up a few more Gb.
    Again it failed. When it fails, itunes leaves the partially restored elements on my hard disk meaning that my 'Apple Computer' folder is now 28Gb!! I cannot afford to delete anything else from the hard disk. I am using a PC by the way. I have noticed that in the folder 'Apple Computer\MobileSync\Backup' has 5 folders in it which is the same amount that I tried to restore the iphone (before the last restore attempt there were 4 folders). These folders amount to 20Gb. From this I am assuming that the actual backup that I made is infact in 'Apple Computer\iTunes\Mobile Backups'.
    Can I delete the folders in 'MobileSync\Backup'? This would free up 20Gb of disk space giving me enough to properly restore (in theory!).
    Thanks for your time!!
    Nick

    your advice worked for me and saved me what ever evil lurked behind my thought to just delete the backup and get back my very lmited space on my 250GB Mackbook Pro using daisydisk pro https://itunes.apple.com/us/app/daisydisk/id411643860?mt=12
    Why DaisyDisk?
    DaisyDisk remains the tool of choice for film makers (including companies like Pixar), digital artists, IT professionals and hundreds of thousands of Mac users worldwide when it comes to disk space management. Constantly improving since its initial introduction, the app easily blows away competition in terms of speed, efficiency and user experience.
    @wjostenMar 27, 2012 4:03 AM Re: Can I delete the files/folders in 'Apple Computer\MobileSync\Backup'?
    Re: Can I delete the files/folders in 'Apple Computer\MobileSync\Backup'?in response to nickcrowney
    Delete iOS backups this way: iTunes>Preferences>Devices...select the backup/backups...hit delete. Do not mess with your backup folder.

Maybe you are looking for

  • How do I use your iPhone with multiple iTunes libraries

    Hi, I have my music spread out between 3 seperate Itunes libraries on 3 different profiles on my computer. I have the newest generation Ipod Nano, Ipod Shuffle, and Iphone 4s. My Ipod's are both full, so I've decided to start putting music onto my ph

  • Scanning of photos

    hi good day one and all. i have a hp deskjet ink advantage 3540 e-all-in one series printer. i was trying to scan a pic measuring 2"x2" and instead of getting a digital image of the same size i got a 2"x1.57" image instead. i used the scan dialogue a

  • ME21N and ME22N

    Dear Gurus, I have a question here. Currently I am using an user exit EXIT_SAPMM06E_013 which is used for transaction code ME21N to check PO before saving. This user exit is to trigger an email to user when there is a creation of PO. The user exit is

  • Inventory movement using logic script - BPC NW 10

    Hello BPC experts, I'm working on inventory movement using logic script. The idea is that the initial stock of the first period equals the final stock of the previous period. Here is an example of my inventory report : (Dimension INVT in function of

  • PLS-00306: wrong number or types of arguments in call to 'p_proc'

    Hi, This code call a procedure which takes a VARRAY type as parameter. I face this error when i compile the code. java.sql.SQLException: ORA-06550: Line 1, column 7 : PLS-00306: wrong number or types of arguments in call to 'p_proc' ORA-06550: Line 1