Releasing File resources after "new File()"

Hi, I'm experiencing the following problem. I'd like to list the properties of files in a directory, so I do something like
File dir = new File(".");
String[] files = dir.list();
for(int i = 0; i < files.length; i++){
System.out.println(new File(files).lastModified());
I gather these calls to "new File()" do hold some read locks to the files, when are these locks released? at GC time? is there anyway to force/guarantee the release?

I gather these calls to "new File()" do hold some
read locks to the files, No, they don't. File just has metada about the file--name, path, size, etc. It doesn't open the file or lock it or anything.
The ones you need to clean up are the Input/OutputStreams and Readers and Writers. Those have close() methods. There's also java.nio.channels.FileLock and associated classes mentioned in its docs.

Similar Messages

  • Mdworker: (Normal) Import: Using too many resources after 64 files

    Spotlight Eternaly indexing no matter what I do. I've deleted indexes, stopped and started mdutil. Everything to no avail.
    Mar  1 08:03:16 server com.apple.launchd.peruser.505[371] (com.apple.mdworker.prescan.0): Throttling respawn: Will start in 5 seconds
    Mar  1 08:03:21 server mdworker[43987]: (Normal) Import: Using too many resources after 64 files (wired: 0 resident: 140065 swapped: 2 regions: 450), hit usage threshold importing /Users/user/Documents/Microsoft User Data/Office 2011 Identities/Main Identity/Data Records/Messages/0T/0B/0M/28K/x00_28975.olk14Message, exiting to clean up now.
    Mar  1 08:03:26 server com.apple.launchd.peruser.505[371] (com.apple.mdworker.prescan.0): Throttling respawn: Will start in 5 seconds
    Mar  1 08:03:31 server mdworker[43991]: (Normal) Import: Using too many resources after 64 files (wired: 0 resident: 140065 swapped: 2 regions: 450), hit usage threshold importing /Users/user/Documents/Microsoft User Data/Office 2011 Identities/Main Identity/Data Records/Messages/0T/0B/0M/31K/x00_31281.olk14Message, exiting to clean up now.
    Mar  1 08:03:36 server com.apple.launchd.peruser.505[371] (com.apple.mdworker.prescan.0): Throttling respawn: Will start in 5 seconds
    Mar  1 08:03:41 server mdworker[43993]: (Normal) Import: Using too many resources after 64 files (wired: 0 resident: 140065 swapped: 2 regions: 450), hit usage threshold importing /Users/user/Documents/Microsoft User Data/Office 2011 Identities/Main Identity/Data Records/Messages/0T/0B/0M/32K, exiting to clean up now.
    Mar  1 08:03:46 server com.apple.launchd.peruser.505[371] (com.apple.mdworker.prescan.0): Throttling respawn: Will start in 5 seconds
    Mar  1 08:03:51 server mdworker[43994]: (Normal) Import: Using too many resources after 64 files (wired: 0 resident: 140065 swapped: 2 regions: 450), hit usage threshold importing /Users/user/Documents/Microsoft User Data/Office 2011 Identities/Main Identity/Data Records/Messages/0T/0B/0M/32K/x00_32815.olk14Message, exiting to clean up now.
    Mar  1 08:03:56 server com.apple.launchd.peruser.505[371] (com.apple.mdworker.prescan.0): Throttling respawn: Will start in 5 seconds
    Mar  1 08:04:01 server mdworker[44032]: (Normal) Import: Using too many resources after 64 files (wired: 0 resident: 142049 swapped: 2 regions: 451), hit usage threshold importing /Users/user/Documents/Microsoft User Data/Office 2011 Identities/Main Identity/Data Records/Messages/0T/0B/0M/33K/x00_33570.olk14Message, exiting to clean up now.
    Mar  1 08:04:06 server com.apple.launchd.peruser.505[371] (com.apple.mdworker.prescan.0): Throttling respawn: Will start in 5 seconds
    Mar  1 08:04:12 server mdworker[44034]: (Normal) Import: Using too many resources after 64 files (wired: 0 resident: 142044 swapped: 2 regions: 448), hit usage threshold importing /Users/user/Documents/Microsoft User Data/Office 2011 Identities/Main Identity/Data Records/Messages/0T/0B/0M/34K/x00_34279.olk14Message, exiting to clean up now.
    Mar  1 08:04:17 server com.apple.launchd.peruser.505[371] (com.apple.mdworker.prescan.0): Throttling respawn: Will start in 5 seconds
    Mar  1 08:04:22 server mdworker[44035]: (Normal) Import: Using too many resources after 64 files (wired: 0 resident: 142046 swapped: 2 regions: 450), hit usage threshold importing /Users/user/Documents/Microsoft User Data/Office 2011 Identities/Main Identity/Data Records/Messages/0T/0B/0M/35K/x00_35086.olk14Message, exiting to clean up now.
    Mar  1 08:04:27 server com.apple.launchd.peruser.505[371] (com.apple.mdworker.prescan.0): Throttling respawn: Will start in 5 seconds
    Mar  1 08:04:32 server mdworker[44039]: (Normal) Import: Using too many resources after 64 files (wired: 0 resident: 142013 swapped: 2 regions: 450), hit usage threshold importing /Users/user/Documents/Microsoft User Data/Office 2011 Identities/Main Identity/Data Records/Messages/0T/0B/0M/36K/x00_36629.olk14Message, exiting to clean up now.
    Mar  1 08:04:37 server com.apple.launchd.peruser.505[371] (com.apple.mdworker.prescan.0): Throttling respawn: Will start in 5 seconds
    Mar  1 08:04:42 server mdworker[44047]: (Normal) Import: Using too many resources after 64 files (wired: 0 resident: 177956 swapped: 2 regions: 660), hit usage threshold importing /Users/user/Downloads/2011-11-14.pdf, exiting to clean up now.
    Mar  1 08:04:47 server com.apple.launchd.peruser.505[371] (com.apple.mdworker.prescan.0): Throttling respawn: Will start in 5 seconds
    Mar  1 08:04:53 server mdworker[44048]: Unexpected EOF, returning last token as fallback
    Mar  1 08:04:53 server mdworker[44048]: Invalid char
    do I Need to reinstall Lion? I am losing my mind trying to fix this.

    mdworker is part of Spotlight indexing.  Spotlight as in Commnad-Space or the magnifying glass in the upper right corner of your menu bar.
    You can control Spotlight via System Preferences -> Spotlight
    Message was edited by: BobHarris

  • Recently updated Mac OS 10.5.8 to 10.6.8 and and can not open exisiting Illustrator5 files or save new files.

    I recently updated my MacBook Pro OS from 10.5.8 to 10.6.8 and can not open existing Illustrator5 files or save new files can someone help?

    I think you have a corrupted upgrade. Do you have a backup of your old system?
    Here's what you should do for now:
    Reinstall OS X without erasing the drive
    1. Repair the Hard Drive and Permissions
    Boot from your Snow Leopard Installer disc. After the installer loads select your language and click on the Continue button. When the menu bar appears select Disk Utility from the Utilities menu. After DU loads select your hard drive entry (mfgr.'s ID and drive size) from the the left side list.  In the DU status area you will see an entry for the S.M.A.R.T. status of the hard drive.  If it does not say "Verified" then the hard drive is failing or failed. (SMART status is not reported on external Firewire or USB drives.) If the drive is "Verified" then select your OS X volume from the list on the left (sub-entry below the drive entry,) click on the First Aid tab, then click on the Repair Disk button. If DU reports any errors that have been fixed, then re-run Repair Disk until no errors are reported. If no errors are reported click on the Repair Permissions button. Wait until the operation completes, then quit DU and return to the installer.
    If DU reports errors it cannot fix, then you will need Disk Warrior and/or Tech Tool Pro to repair the drive. If you don't have either of them or if neither of them can fix the drive, then you will need to reformat the drive and reinstall OS X.
    2. Reinstall Snow Leopard
    If the drive is OK then quit DU and return to the installer.  Proceed with reinstalling OS X.  Note that the Snow Leopard installer will not erase your drive or disturb your files.  After installing a fresh copy of OS X the installer will move your Home folder, third-party applications, support items, and network preferences into the newly installed system.
    Download and install Mac OS X 10.6.8 Update Combo v1.1.

  • Cannot open files or create new files in Photoshop cc trial

    Hi,
    after getting no support from your phone support line. I am writing here in hopes that this issue can be resolved. I cannot open files or create new files in Photoshop CC trial. Please help

    You can open Photoshop, you cannot create new documents. If you click file>new, the normal new dialog box opens, if you click "ok" it goes away. If you double click a PSD it focuses the Photoshop window. Nothing else happens.
    For me this is a new issue today. My computer is an i7/780, more than capable of Photoshop, and has run it fine up until now. My keyboard started freaking out last night and doing things I didn't want it to. I suspect it changed a setting or broke something.
    I have uninstalled and re-installed and it did not resolve the issue.
    This is obviously a critical issue that needs immediate attention.

  • How to get the file content after uploading file

    Hello everyone!
    I have a question. Anyone can provide an example code by jsp that getting the uploaded file content after user uploading a file?
    Your help is highly appreciated!!!

    My experience is you need to do it twice: first read it to a StringBuffer and readline. Then write the file to server. See the code below
    MultipartParser parser = new MultipartParser(request, 10000000);
    Part part = null;
    FilePart filePart = null;
    File uploadDir = new File("/Uploads/");
    if (!uploadDir.exists()) {
    uploadDir.mkdir();
    while(true){
         part = parser.readNextPart();
         if(part == null)
              break;
         if(part instanceof FilePart){
              filePart = (FilePart)part;
              filename = filePart.getFilePath();
              //You can do one of the following option. Here is read line to a buffer and display to screen
    //if (filename != null) {
              //Do not store the file to server machine.
    //long size = filePart.writeTo(uploadDir);
    // System.out.println("The number of bytes written is "+size);
              reader = new BufferedReader(new InputStreamReader(filePart.getInputStream()));          
              String newline=reader.readLine();
              if(newline!=null)     {     
              reconcileContent.append("<table border=\"1\"><tr><th>Destination ID</th><th>File ID</th><th>Rept Date</th><th>As of Date</th><th

  • XML file conversion after sender file content conversion

    Hi,
    I have issue refarding file content conversion.
    My input structure is
    <MT_RCICrecords>
    <TRNH>
      <RCIC>
        <RECH>
        <RECL>
      <RCIC>
    <TRNH>
    Afetr sender File content conversion (csv to xml) it produces xml file as below (since file conversion does not support 3rd level of hierarchy)
    <TRNH>
    <RECH>
    </RECH>
    <RECL>
    </RECL>
    </TRNH>
    It does not recognize RCIC.
    Now i am trying to map this to IDOC and getting error as
    'MT_RCICRecords tag found instead of IDOC BEGIN ='.
    CAn anyone suggest me how to chaage this xml output after File content conversion to add RCIC tag in xml file?
    I am new to XI so please give me some sample code to.
    Thanks.
    Yashpal
    Its urgent!

    My problem is xml generated from content conversion is like below
    <MT_RCICrecords>
    <TRNH></TRNH>
    <RECH></RECH>
    <RECL></RECL>
    <TRLR></TRLR>
    </MT_RCICrecords>
    and i want it to be
    <MT_RCICrecords>
    <TRNH></TRNH>
    <RCIC>
    <RECH></RECH>
    <RECL></RECL>
    </RCIC>
    <TRLR></TRLR>
    </MT_RCICrecords>
    which is not happening
    My input message structure is
    MT_RCICrecords
    TRNH
    RCIC
    RECH
    RECL
    i hope it is clear now
    TRLR

  • Saving tiff or jpg files within a single, existing psd file without creating new files

         Hi, I just bought CS5 and I wonder if it is possible to save multiple images that are created within a single psd file in jpg or other image file formats without creating new psd files, but rather saving them as "embedded" within the single psd file in whih they are created. For example, one could select a portion of an image that one has created, and save just that selection as a jpg without leaving the existing psd file, and after that, one could select another portion of the same image and save it as a tiff, etc. Is this possible?
    Much thanks.

    No and Yes!
    You can do much of what you want, but not exactly as you described it.  You can certainly make multiple selections and have them saved in the psd file. You can also save jpg version of those selections, but you have to do a little extra work.
    Lets say, by way of example, you have an image and you want to make three different selections within that image, save each selection as a jpeg, and save those selections along with the full image as a psd file. You can do the following, which is just one way of several to proceed, with your image opened.
    1. Make selection 1, hit Ctrl+J to jump that selection to a new layer
    2. Make selection 2, hit Ctrl+J to jump that selection to a new layer
    3. Make selection 3, hit Ctrl+J to jump that selection to a new layer
    4. Alt click on the layer with selection 1. This makes only that layer visible.
    5. Click on Layer > Duplicate Layer > destination New > give it a name
    6. This creates a new (temporary document). Open it.
         click Image > Trim > transparent pixels
         click Save for Web & Devces, select your parameters and save your jpeg
         Close and discard this temporary file.
    7. Repeat steps 4,5 & 6 for selection 2 & selection 3
    8. Save your psd file
    You now have three jpegs and a psd file with all the information to create or modify the original selections
    Paulo

  • Error running exe to write to exel file: Error 7 New file not found

    Hello!I have this problem, i've looked everywhere and i still can't solve it. It would be great if anyone can help me.
    I built an application that writes an array to a spreadsheet file.
    Everything works fine in Labview 7.1 , i can build the exe file, but
    when i try to run it it doesn't work (it doesn't do anything although
    in Labview works perfecty well)and i have this error:
    <<Error 7 occurred at New File; Possible reason(s):
    LabVIEW:  File not found. The file might have been moved or
    deleted, or the file path might be incorrectly formatted for the
    operating system. For example, use \ as path separators on Windows, :
    on Mac OS, and / on UNIX.>>
    I've attached the vi file and the exe file.
    Thank you
    Attachments:
    app.zip ‏167 KB

    You've made a very, very common mistake and one discussed in numerous postings. When running in development mode and using the Current VI's Path, the path to a VI would be something like c:\folder\example.vi. When built, it becomes c:\folder\app.exe\example.vi. An extra strip path is required. Look at this, this, and this.

  • Reading and writing u16 binary file to a new file

    Hello all,
    a very simple thing that I just don't seem to be able to figure out. I have a file containing 1024bytes of unsigned 16bit words. I can read it successfully with the right value  being displayed. But then I try to write these values to a new file, I can no longer read the same value (in fact it's all grayed out 0) from the newly written file. The newly written file has the right size 1024 bytes, but I don't seem to obtain the right information. I made sure the endian are the same, little-endian.
     Attached is my basic VI, and the .dat file is the file containing the binary information. 
    I'm not using copy file because once I get this figure out, I'll need to append more of the Scan.dat file to one single file. 
    Thank you!
    Solved!
    Go to Solution.
    Attachments:
    read_write_binary_u16.zip ‏11 KB

    I would put some wait time between the write and the read.  It may be a good idea to actually close the file in between.
    I have a feeling that you may not have allowed enough time to actually have the file written out before you read it again.  That or since it is still open, the file pointer is at the end of the file and you are trying to read all the bytes starting at the end, which means you get nothing.
    Not sure of the exact issue, but those two things comes to mind.

  • Check file type after JavaScript File.openDialog()...

    So, I'm on Mac OS and want my script to obviously cancel on the "Cancel" bottle, as well as check whether the file selected was a PDF. I've had some success with the code below, but some of the PDF's I select get cancelled with this script. Upon checking, the FilePath.type property returns "????" for some PDF's - anyone know why?
    var myFilePath = File.openDialog("Please choose a PDF file...", undefined, false);
    if((myFilePath == "") || (myFilePath == null)){
        exit();
    else if(myFilePath.type != "PDF "){
        alert("Please choose a PDF file!") ;
        exit();
    I'm quite new to scripting. Thank you!

    Under Windows, all you can do is supply a file extension (the well-known "*.PDF" filter), and it's wise to always add the catch-all "*.*" for 'All files'. That way, a user can select a file even if it has the wrong extension (and in that case, it's the user's responsibility to make sure the file is of the expected type nevertheless).
    Under OSX, there are two options:
    1. The file has the correct "Creator/Type" metadata; and/or
    2. The file has the correct file extension.
    Historically, Macintosh-based OSes used option #1, and software was not expected to look at the actual file names. However, that soon became unworkable when people tried to exchange files between their Mac and (virtually any) other systems. That lead to various tools to 'assign' Creator/Type data to well-known file extensions, just so they could be opened with the right software on a Mac. Also the reverse happened; saving a file 'without extension' on a Mac was not a problem, but to open it on Windows you often had to add the right extension.
    So, somewhere around one or two System versions ago, Apple decided to go back to the old, trusted 'File Extension' way. But OSX still saves Creator/Type metadata for files created on your own Mac. Checking the "type" should work then -- but the problem is, what if you got your file from somewhere else? The extension may be correct, but if it has no file type, your script will not see it.
    Fortunately, the Mac OSX File Open dialog allows some pretty wicked customizations. Never mind a file filter, you can run a custom function that decides for each separate file and folder whether it should be selectable or not. The function has access to all file attributes; you can go so far as to checking the file name, and reject all files that contain a 'q', or files that are read-only, or files that are smaller than 1Kb.
    Check out this piece of code (I wrote it myself, but various hints and tricks were read on this very forum):
    if (File.fs == "Windows")
        pdfFile = Folder.myDocuments.openDlg( 'Load PDF document', "Adobe PDF:*.pdf,All files:*.*", false);
    else
        pdfFile = Folder.myDocuments.openDlg( 'Load PDF document', function(file) { return file instanceof Folder || (!(file.hidden) && (file.name.match(/\.pdf$/i) || file.type == "PDF ")); }, false );
    (I advise you to copy the Windows fragment as well, just in case your script goes 'round the world.)

  • New File("C:") vs new File("C:\\") ?

    Hi all
    Can someone help me with why new File("C:") creates a File that points to the current working directory?
    A simple test program:
    import java.io.File;
    public class Test {
         //C: is the root partition of my hard drive
         //D: is another partition of that same hard drive
         public static void main(String[] args) {
              System.out.println(new File("C:").getAbsolutePath());
              System.out.println(new File("C:\\").getAbsolutePath());
              System.out.println(new File("D:").getAbsolutePath());
    }Output:
    C:\Documents and Settings\Anthony\Desktop
    C:\
    D:\
    So why doesn't new File("C:") behave as i expect it to behave, i.e. the same as new File("C:\\") & analog to new File("D:") ?
    Thanks in advance
    Anthony

    I suspect the answer to that is that "C:" is not a folder path it is a raw drive designation in Windows.
    It is presumably similar to when you are using a CMD/DOS window and from the D drive you go cd C:\myfolder, and are surprised when you're still on the D drive.
    ... and if you don't supply a path, by default files go into your "home" directory.

  • Illustrator files dissapear after saving files

    hi
    we are all working on a network, mac computers all running mavericks. It started to happen few days ago that .ai files dissapear after editing and saving.
    any solution?
    Thanks!

    gonzalom,
    It is always recommended here to open/save from/to own hard disk, and to copy from/to networks and removable media. You may be lucky (for a while), but the chances of file corruption and other unpleasantnesses are immensely greater when you use anything but the harddisk, and it is better to be safe than sorry.
    In addition to the (far greater) risk of file corruption, some issues are mentioned here:
    http://helpx.adobe.com/illustrator/kb/illustrator-support-networks-removable-media.html

  • Xml adapt an old file to a new file

    I have this problem in Labview 2011: I have an old XML file created with Labview blocks from a cluster. Now I need to modify that cluster adding some variables inside. How can I insert the variables in the XML file (with a default value) without throwing away all the old data?
    I need a universal method and I know that won't be simple, but I'll appreciate teh simplest.
    Thank you in advance

    There is no "universal" method.
    You have two choices:
    Create a VI that reads in the old file and puts the information into the old cluster. Then repackage the data into the new cluster, adding the new data. Then write out the file in the new format.
    Update the XML file manually. Did you use the Write to XML VI? If so, you are using the LabVIEW schema. This schema is documented in the LabVIEW Help, so you can read it and then modify the file using a simple text editor. Did you use the XML Parser VIs? If so, you are using your own schema, and you can modify the XML file accordingly. 

  • Lightroom Files missing after new drive added

    I recently filled up my old hard drive(F:) so I went out and bought a new and larger one. Without realizing it the new one was now the F drive and my old one is now the H drive. But Lightroom can not find all of my files in my old drive and I think it is because it is now located on the H drive. I don't want to loose the new photos I put on the new drive (now the F drive). What can I do? If I re-import the old drive will it recognize all my old files?
    Help?....

    Do not re-import. If you do so, you'll lose all your work on those files.
    In the Folders panel in Lightroom, right-click on the highest-level folder and choose Find missing folder from the context menu. In the dialogue box that comes up, navigate to that folder on your H: drive and select it. All the images in that folder and all its children, grand-children, etc. will be reconnected with your Lightroom catalogue. If you have more than one top-level folder, repeat with the others.
    Hal

  • Elements 11 accepts no *.arw files even after new installation and camera raw modul 7.4. Under open files as Camera Raw the *.arw file is listed.

    After trying all options provided by Adope I cannot open *.arw files under Elements 11.

    You need camera raw 8.3 for your camera. It is only compatible with PSE12 or PSE13. Alternatively, download and install the free Adobe DNG converter to convert your raw files to the Adobe universal Raw format and the files will open in all versions of PSE (keep your originals as backups and for use in the camera manufactures software)
    Windows download (.exe file) click here DNG Converter 8.3
    Mac download (.dmg file) click here DNG Converter 8.3
    You can convert a whole folder of raw images in one click. See this quick video tutorial:
    You Tube click here for DNG Converter tutorial

Maybe you are looking for

  • Right-click Flash selection of webcams no longer works. Bug?

    After some tense struggles and several failed webcam swaps, our support team discoverd that using right-click to select a webcam no longer works after our hosted service's recent upgrade. Is this necessary, or a bug?

  • Where to ask question re: Apogee GiO?

    I see 14 questions under the GIO entry, but no place to ask a question. In the main index to topics there are plenty of areas to ask Logic/GarageBand, (etc) questions. But the questions that appear, now, on the GIO page are not listed back in the for

  • HELP! Beginning JSP with JavaBean Class

    First of all, I'm using jdk1.4 beta and Jakarta's tomcat version 4.0.1 release build. Hello. I desparately need help. I have a JavaBean class ("CarBean.class") saved in %catalina_home%\webapps\root\myapp\web-inf\classes\com\wrox\cars\CarBean.class I

  • Printing form multiple times

    Hi Experts, how to print the form multiple times? . i have multiple shipto entries....for every new shipto entry form should be printed..can you please provide me with sample code..

  • After update sticks on "updating itunes library".

    After installing the new updates several times, both quicktime and itunes. When I click on itunes it opens up and gets stuck on the updating ituns library. When I look on the task manager it says itunes not responding. Any suggestions.