Stroring certain details in a file, But Could not delete the File.

I am storing certain details using serialization. But when i decide to delete the File i am unable to delete the File. I am attaching a sample Code to understand my problem.
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
public class SerialDemo implements Serializable {
  public static void main(String[] args) {
    try {
        FileOutputStream f = new FileOutputStream("./test.proj");
        ObjectOutputStream s = new ObjectOutputStream(f);
        SerialDemo d = new SerialDemo(5);
        s.writeObject(d);
        s.flush();
        FileInputStream f = new FileInputStream("./test.proj");
        ObjectInputStream s = new ObjectInputStream(f);
        SerialDemo d = (SerialDemo) s.readObject();
        System.out.println(d.getIndex());
        s.close();
        f.close();
        System.out.println("SerialDemo.getVal() is: " + d.getVal());
      File file = new File("./test.proj");
      System.out.println(file.delete());
    } catch (Exception e) {
      e.printStackTrace();
  int test_val = 7; // value defaults to 7
  public SerialDemo() {
    super();
  public SerialDemo(int x) {
    super();
    test_val = x;
  public int getVal() {
    return test_val;
  private int idx = 2;
  public int getIndex() {
    return idx;
  static final long serialVersionUID = -4717603181820250815L;
}

Glad I could help. I recommend you look into using FindBugs, it will warn you of this kind of thing. Also change the way you open/close streams to:
YourStream stream = null;
try {
   stream = new YourStream();
   // read/write from
} finally {
  try {
     stream.close();
  } catch( IOException ioe ) {
      // Log the IOE. Or use the IOUtils.quiteClose from Commons IO.
}As otherwise you could leave the stream open, i.e. if the read() method throws an IOE.

Similar Messages

  • Unzip issue: Could not delete the zip file after unzip it

    I have issue with the following code, the purpose is to unzip first then delete the zip file. But I could not delete the zip file. When I put a break point before my delete() call, I manually delete it and get the file is used by another process. Please help. Here is my code;
    try{
    File primeZip = new File(dir, fileName);
    ZipInputStream zipStream = new ZipInputStream(new FileInputStream(primeZip));
         ZipFile zf = new ZipFile(primeZip);
         OutputStream out = null;
         for (Enumeration em = zf.entries(); em.hasMoreElements();){
              String fileName = em.nextElement().toString();
              out = new FileOutputStream(fileName );
              byte[] buf = new byte[16384];
              int len;
              while ((len = zipStream.read(buf)) > 0) {
                   out.write(buf, 0, len);
              out.flush();
              out.close();
         out.flush();
                   out.close();
                   zipStream.close();
    primeZip.delete();
    }catch(FileNotFoundException e){          
    }catch(IOException e){         
    }

    I put close() for ZipFile object which is zf.close() befoer I delete the zip file resolve this issue.
    Thanks.

  • ColdFusion could not delete the file

    Good day all im getting this error. cant figure it out
    "ColdFusion could not delete the file
    c:\ColdFusion8\wwwroot\Jewel\images\stock\203083.jpg for an unknown
    reason"
    I tried installing the 801 update the patch using :
    http://kb.adobe.com/selfservice/viewContent.do?externalId=kb403622&sliceId=1
    http://kb.adobe.com/selfservice/viewContent.do?externalId=kb403411&sliceId=1
    However this does not seem to be working,... but the file is
    there...
    Does anyone have a solution to this problem

    you sure you have all hotfixes installed? this was definitely
    fixed in
    one of the recent ones...
    also, i am no quiet sure about referencing [previous] cffile
    inside
    another cffile tag:
    <cffile action="rename"
    source="#dirlocation#\images\stock\#CFfile.serverfile#"
    destination="#dirlocation#\images\stock\#FORM.code#.jpg">
    see if setting a RESULT attribute in your cffile
    action='upload' tag and
    referencing that instead in your cffile action='rename'
    solves the
    problem...
    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com/

  • HT204686 I bought an iPhone 4 from a youngster who had put his own Apple ID on it but could not remember the password. I backed it up yesterday and restored to my new iPhone and it copied the Apple ID across too. Now I have 2 phones with it on. Anything I

    I bought an iPhone 4 from a youngster who had put his own Apple ID on it but could not remember the password. I backed it up yesterday and restored to my new iPhone and it copied the Apple ID across too. Now I have 2 phones with it on. Anything I do?

    that must be really annoying !!
    so this is what you call
    FIND MY IPHONE ACTIVATION LOCK Find My iPhone Activation Lock - Apple Support
    when you start using iCloud on any iOS device and enable find my iPhone, this prevents  a new user from using it, and also prevents anyone from using the phone
    as it is locked to previous owners account ,this is also the case if when a phone is lost or stolen.
    the only way around this is to have the previous owner reset their apple id by going to  @ applied.apple.com
    if they are unable to do this, then the only other way around this is to have the previous owner get  a copy of their original receipt and call apple support who can then lift this lock if they get a copy of the receipt
    unfortunately there is no quick fix -> the below link explains what you should do before you sell or give away an iPhone
    What to do before selling or giving away your iPhone, iPad, or iPod touch - Apple Support

  • Firefox does not fully load Barclaycard Authentication site. It loads as far as asking for certain letters in my pasword but does not load the "Submit" button so I cannot continue with my purchase and have to switch to IE8 browser to purchase anything ov

    Firefox does not fully load Barclaycard Authentication site. It loads as far as asking for certain letters in my pasword but does not load the "Submit" button so I cannot continue with my purchase and have to switch to IE8 browser to purchase anything over the internet. Any clues?
    == This happened ==
    A few times a week
    == Couple of weeks ago

    Your UserAgent string in Firefox is totally messed up by another program that you installed, and Barclays doesn't know you are using Firefox 3.6.6 - it probably looks like IE 6.0 to that website.
    [http://en.wikipedia.org/wiki/User_Agent]
    type '''about:config''' in the URL bar and hit Enter
    ''If you see the warning, you can confirm that you want to access that page.''
    Filter = '''general.useragent.'''
    Right-click the preferences that are '''bold''', one line at a time, and select '''''Reset''''',
    Then restart Firefox

  • How do I open RAW images from DSC_RX100M3?  I downloaded Adobe DNG converter 8.4, but could not convert the images?

    How do I open RAW images from DSC_RX100M3?  I downloaded Adobe DNG converter 8.4, but could not convert the images?

    Small correction to what SSprengel wrote...
    The RX100M3 is supported only by version 8.5.  It sounds like you need a newer version.
    Photoshop Help | Digital Negative (DNG)
    -Noel

  • ColdFusion could not delete the file [file path] fo

    Using the <cffile> tag I write a file to the server and
    display the outputed file in my browser. I then try to delete the
    file. I get the error message ColdFusion could not delete the file
    [file path] for an unknown reason. If I wait 60 seconds I can
    successfully delete the file. Using the freeware prodram Unlocker I
    know that it is a jrun.exe process that is preventing the deletion
    of the file for the 1 minute after the file has been created.
    Is there a known workaround or fix for this issue?

    Are you using CFlock when you write or create the file? If so
    that will prevent the file from being deleted until the lock is
    released.

  • What do I do?I can open youtube but could not play the video's? I can play the video in youtube when I use Explorer.

    I have updated to Firefox 14.01 and Java.
    I could open youtube but could not play the video's.
    But when I use Internet Explorer the video in youtube is fine.
    What should I do?

    There are some compatibility issues between the latest Flash player and some Firefox add-ons or settings.
    * Support article with workarounds: [[Flash 11.3 doesn't load video in Firefox]].
    * If you want to keep using your Real downloader, consider disabling the new protected mode in Flash 11.3. See this support article from Adobe under the heading "Last Resort": [http://forums.adobe.com/message/4468493 Adobe Forums: How do I troubleshoot Flash Player's protected mode for Firefox?]

  • Time Machine Backup Error. Time machine could not delete the backup disk image .sparsebundle

    Time Machine is giving an error message.  Time Machine couldnt complete the backup.  I am using the Seagate GoFlex Home.  Error message states Time Machine could not delete the backup disk image "/volumes/Go Flex Home Backup/iMAc.sparsebundle".  Does anybody have any ideas?

    I have deleted all files in the Time Machine backup via Windows, Finder, and GoFlex UI.
    I think this is your problem.. you need to follow the exact setup from seagate to get TM running again.. please read the manual... I do not have one but I do have another brand of NAS and setting up TM involves a fairly complex set of instructions.. because it is not a native Apple device.. your computer does not recognise it as TM capable.. you need to use the work around the manual will explain.

  • "Time Machine could not delete the backup disk"

    This morning, I got the "Time Machine must create a new backup for you" message referred to here:  http://pondini.org/TM/C13.html
    I went ahead and told it "start new backup" but after a few minutes, got this message, ending in error message -1:  "Time Machine could not delete the backup disk."  It did not reference a sparsebundle file or some other specific file name as I've seen in some other threads, and I haven't been able to find this exact issue anywhere in the forum or on Pondini's page.
    I went ahead and told it manually to do a new backup, but I am concerned that it will "lie to me" about the verifiability of the files per Pondini's page above (orange box at the bottom).  I'll attempt to force it to manually verify once this backup completes to see what happens, I guess.
    I'd appreciate any input.

    And now an effort to manually start a backup produces this error:  "This backup is too large for the backup disk. The backup requires 233.73 GB but only 188.30 GB are available."

  • Error: "The workflow could not delete the list item"

    Have set up 2 lists:  Events and EventsArchive.  They have all the same fields.  I have created a workflow in SPD using an impersonation step (I have Full control of the site/site collection).  Workflow is essentially this:
        If Curent Item:Expired 
    equals
    Yes
           Copy item in Current Item to
    EventsArchive
           then Delete item in
    Current Item.
    The item is copying over to the EventsArchive list just fine, but the "delete" part is not happening.  Instead, I get the following error:
    The workflow could not delete the list item. Make sure the list exists and the user has permissions to delete items in the list.
    The list obviously exists (or I wouldn't be able to copy an item from it), and I have as much permissions as anyone can have, so I'm not sure where else to turn with this. 
    Thanks in advance for your help!

    Hi,
    To test the issue, I create a simple workflow without using Impersonation step:
    It works.
    Could you please create new lists to avoid custom settings and test the issue again?
    Similar thread:
    https://social.msdn.microsoft.com/Forums/office/en-US/3fa94026-4487-4e4c-a5b4-12a79d6ee6a2/workflow-delete-item-not-working?forum=sharepointcustomizationprevious
    Regards,  
    Rebecca Tu
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • APD - I'm trying to send a File to AS but 'Could not close the file 'AP_DP'

    Dear Expert,
    I'm trying to sen a file to Application Server through Analysis Process Design, but the messega that the log show is:
    Could not close the file 'AP_DP'; operating system error: 9 (Bad file descriptor)
    I have three compoent in the analysis process:
    DataSource:
    Query
    Transformation:
    Hidden Column
    Aggregation
    Data target:
    A PC file.
    When a activete and execute the file doesn't save in the Application Server.
    Please give some advise regarding this case,
    Thanks for your time,
    Luis

    We have authorization problem, restric by OHD technical name.

  • HT1095 Media browser does not come up as an option I burnt to dvd on desktop but could not loop the movie and it will not play on tv dvd player, only on computer.

    I burnt my iMovie onto dvd but could not see how to make it looped. When completed it will only play on my computer not my tv dvd player. Please help.

    Thank you very much.
    My husband came home and remembered how to do it on dvd, all sorted.
    http://youtu.be/WaC4mkOHnOY
    You can see it, its rather a slow 7 mins as I am drawing in real time, but you can hurry it by whooshing through if you like, you see the subject of the drawing towards the end to compare with the drawing.

  • I made a Blurb book through Lightroom 5, on another computer, backed it up on an external hard drive and tried to import it into my imac.  I got the picture files, but could not get the book I had worked on.  How do I find my book?

    I made a 'Blurb' book using Lightroom on a computer that was not mine.  I backed up the book on an external hard drive and then tried to import the book into my imac.  I wasn't able to retrieve my book.  The photos I used for the book project are there, but the 45 page book I made is not there.
    What do I need to do?

    You would need to go to the computer containing the book.
    Select the saved book in the Collection panel.
    Go to Grid View [ G ] and select all the images [Cmd/Ctrl][A]
    File>Export as Catalog and store on media you can use to transfer
    Bring this catalog onto your computer
    File>Import from another catalog and bring the transitory catalog into your master catalog.
    It should bring the images, your collections (including your book) and other settings into your own catalog.

  • I can't run itunes or install updates now due to teh MSVCR80.dll file not found and APS Daemon.exe being nable to locate a component ofn Windows vists.  A MS user suggested uninstalling all Apple programs.  I did this but could not uninstall the Apple Mob

    I have been getting error messages  .n MS windows the APS Daemon ,exe is unable to locate a component and the itunes updates and program failed to start because MSVCR80,dll was not found.  As advised I have uninstalled all Apple Inc. programs except the Apple Mobile Device program.  Then I reinstalled itunes but still get the errors and can't run itunes.  Advice....

    See Troubleshooting issues with iTunes for Windows updates.
    tt2

Maybe you are looking for

  • Worst customer experience I have ever had

    For a start try googling Bt and watchdog and you will see how bad it is. My story begins with getting a line with Bt this was a horrendous business in the first place as our new house had no connection, so we had to pay to improve Bt's network by get

  • FINDER - Sidebar Font Size

    FINDER - Sidebar Font Size I'm using Mac OS X v10.5.8 & have been trying to find a way to I increase the font size in the sidebar of FINDER. Has this actually been fixed or is there a 3rd party app that will allow me to do this much like in mail! but

  • I am just unpacking a new IMac with Mountain Lion software & I can't find the DVD disks

    I would like to make sure I don't toss out the DVD install disks Thanks Gene

  • How to find my external hd in mac, connected trough my router

    Hi I am new to mac and this forum. I do have a WL router to control my home network and through this router i have mounted an external HD to share files through my network. How do I  find anf connect to it in mac?   - thanks a lot newbe!!

  • Elements 10 and .tif files and set as default???

    I have a new Dell All-In-One built to run Windows 8, but on which I have installed Windows 7. I transferred the contents of my old computer to my new one using PC Mover. Elements 10 works somewhat. Two problems: First I can not set Elements 10 as the