File.exists() returns false for existing file, help :)

Hi all,
I'm having the STRANGEST behavior... I'm working on a simple DNS management system, and before I overwrite a zone file, I want to check if it exists... but exists() is returning false even when the file exists.
Here is my code snippet:
finest( "Checking the existance of "+filename ) ;
File zoneFile = new File( filename ) ;
if ( zoneFile.exists() ) {
    finest( "Zone File "+zoneFile+" already exists." ) ;
    throw( new ZoneFileExistsException( fqdn ) ) ;
else {
    finest( "Creating Zone File "+zoneFile ) ;
    ...It's producing this in the log (I cut off the timestamp parts):
Checking the existance of /opt/DNS/db.testingbutler222.com
Creating Zone File /opt/DNS/db.testingbutler222.com
but...
# ls -l /opt/DNS/db.testingbutler222.com
-rw-r--r-- 1 root other 733 Aug 27 19:23 /opt/DNS/db.testingbutler222.com
So... as you can see, the file CLEARLY exists... what the heck am I doing wrong or misunderstanding? This can't really be a bug in File, can it?
Kenny Smith

Hi,
Thanks for your response, but as I showed in my first post, I'm using absolute paths. My log file contains this:
Checking the existance of /opt/DNS/db.testbutler222.com...
Existance of /opt/DNS/db.testbutler222.com=false
# ls -l /opt/DNS/db.testbutler222.com
-rw-r--r-- 1 root other 695 Aug 29 12:17 /opt/DNS/db.testbutler222.com
I don't understand what is happening... I wrote a separate class that just tests the existance of a file, and that one is reporting the existance correctly.... (the source code is found in the second post above) I don't understand why my servlet code can see the file.
I have jakarta-tomcat running as root, and the file I'm checking was created by the same servlet. I've double checked permissions and such, just to make sure it wasn't that.. but it's still not working.
I even added code to create a FileReader from the file, that way if it throws a FileNotFoundException, I would know the file doesn't exist... and even though the file does exist, it throws the exception. :(
Kenny

Similar Messages

  • DataLine isRunning() always returns false for mp3 files

    Running JDK 1.5.0-b64 on Win 2K and XP. Using the sun mp3 plug-in. Everything works except the DataLine.isRunning() method always returns false.
    For other file types (e.g. WAV) isRunning() returns true/false values as you might expect.
    Anybody else have this experience? It seems like a bug to me.
    Thank you.

    Running JDK 1.5.0-b64 on Win 2K and XP. Using the sun mp3 plug-in. Everything works except the DataLine.isRunning() method always returns false.
    For other file types (e.g. WAV) isRunning() returns true/false values as you might expect.
    Anybody else have this experience? It seems like a bug to me.
    Thank you.

  • File.exists returns false

    File.exists returns false if the File object represents a symlink that is pointing to a non existing file.
    How can I make it return true? I am using File.exists in a condition to
    check if a symlink exists before calling File.delete.
    I am using JDK 1.1.8.
    Any help is appreciated.
    Anil

    Interesting. But it doesn't hurt to call delete() even the File doesn't exist, does it? Could you clarify why you need to confirm that before calling delete()?
    PC

  • File.exists() returns false even when the file exists

    hi,
    the exists() function of java.io.File function returns false even when the file exists on the file system. why is this? i checked the path of the file which gives me the correct path, but exists returns false. can anyone help?

    post some of the code you�re using - then maybe I can help you out
    //Anders

  • I have acquired windows office 2011 for my macbook but unable to open it. There are currently 3 files in the folder, 1 of which seems to be the actual program which is a hfs file. iv tried looking for programs to help me open it but failed

    i have acquired windows office 2011 for my macbook but unable to open it. There are currently 3 files in the folder, 1 of which seems to be the actual program which is a hfs file. iv tried looking for programs to help me open it but failed.
    when double clicking on the image it says unable to open and gives me the option to search the app store.
    any help would be much appreciated
    Adam

    Well, first, just make sure it's the Mac version and not the Windows version (which indeed would not run on your Mac). You say "Windows Office" which is why I mention it. I think you probably just mean "Microsoft Office" though.
    Next, is this on a disk (DVD), or did you purchase and download it from the Microsoft site?
    Matt

  • How to get the file size (in bytes) for all files in a directory?

    How to get the file size (in bytes) for all files in a directory?
    The following code does not work. isFile() does NOT recognize files as files but only as directories. Why?
    Furthermore the size is not retrieved correctly.
    How do I have to code it otherwise? Is there a way of not converting f-to-string-to-File again but iterate over all file objects instead?
    Thank you
    Peter
    java.io.File f = new java.io.File("D:/todo/");
    files = f.list();
    for (int i = 0; i < files.length; i++) {
    System.out.println("fn=" + files);
    if (new File(files[i]).isFile())
         System.out.println("file[" + i + "]=" + files[i] + " size=" + (new File(files[i])).length() ); }

    pstein wrote:
    ...The following code does not work. Work?! It does not even compile! Please consider posting code in the form of an SSCCE in future.
    Here is an SSCCE.
    import java.io.File;
    class ListFiles {
        public static void main(String[] args) {
            java.io.File f = new java.io.File("/media/disk");
            // provides only the file names, not the path/name!
            //String[] files = f.list();
            File[] files = f.listFiles();
            for (int i = 0; i < files.length; i++) {
                System.out.println("fn=" + files);
    if (files[i].isFile()) {
    System.out.println(
    "file[" +
    i +
    "]=" +
    files[i] +
    " size=" +
    (files[i]).length() );
    }Edit 1:
    Also, in future, when posting code, code snippets, HTML/XML or input/output, please use the code tags to retain the indentation and formatting.   To do that, select the code and click the CODE button seen on the Plain Text tab of the message posting form.  It took me longer to clean up that code and turn it into an SSCCE, than it took to +solve the problem.+
    Edited by: AndrewThompson64 on Jul 21, 2009 8:47 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • File.exists() returning false eventhough in reality the file exists

    Hi,
    I am trying to create a PDF file using FDFMerge software.
    For creating the PDF file, I need to execute a shell script from command-line, which I am doing using "Runtime.exec".
    ( I opted for this 'RunTime.exec' approach so as to read the output generated by the shell script.)
    After executing the shell script and reading all the output generated by the process, I am trying to check if the PDF file exists in the location the process created.
    When I do File.exists() its returning me "false" eventhough in reality the file exists.
    Any guess, why this is happening?
    Thanks in advance.
    -Sudheer

    Hi,
    I am trying to create a PDF file using FDFMerge
    software.
    For creating the PDF file, I need to execute a shell
    script from command-line, which I am doing using
    "Runtime.exec".
    ( I opted for this 'RunTime.exec' approach so as to
    read the output generated by the shell script.)
    After executing the shell script and reading all the
    output generated by the process, I am trying to check
    if the PDF file exists in the location the process
    created.
    When I do File.exists() its returning me "false"
    eventhough in reality the file exists.
    Any guess, why this is happening?
    Thanks in advance.
    -SudheerI know the following method works for checking if a file exists...
    public LineCounterB1()
              super( "GUI File reader" );
              tField = new JTextField("c:..\\FileScanner\\source\\test\\LineCounterB1.java");
              tField.setBackground(backColor1);
              tField.setForeground(foreColor1);
              tField.addActionListener( this );
    public void actionPerformed( ActionEvent ae )
              File name = new File( ae.getActionCommand() );
              if( name.exists() )
                   oArea.setText("FOUND " + name.getName() + "\n" +
                        (name.isFile() ? "File\n" : "Not a File\n" ) +
                        (name.isDirectory() ? "Directory\n" : "Not a Directory\n" ) +
                        (name.isAbsolute() ? "Absolute path\n" : "Not Absolute path\n" ) +
                        "Last modified" + name.lastModified() );
                   if( name.isFile() )
                        try
                             BufferedReader reader = new BufferedReader( new FileReader( name ) );
                             StringBuffer buffer = new StringBuffer();
                             String text = null;
                             oArea.append("\n\n");
                             while((text = reader.readLine())!=null)
                                  buffer.append(text + lineSep);
                             oArea.append(buffer.toString());
                        catch( IOException ioE)
                             JOptionPane.showMessageDialog(null,"Oooooo...");
                        //S7 scanner7 = new S7(/**name**/);                                        
                   else if( name.isDirectory())
                        String directory[] = name.list();
                        oArea.append("\n\nDir contents:\n");                    
                             for( int i=0; i<directory.length; i++)
                                  oArea.append( directory[i] + "\n");
              else
                   JOptionPane.showMessageDialog(null, "No such file or directory.");
         }

  • File Doesnt Exist / Returns false

    Hi Folks,
    I was just mucking around with some file IO and I used the following code to try verify a files existence before trying to open it:
    File Temp1 = new File(fullyQualifiedFileName);
         System.out.println(Temp1.getAbsolutePath());
         doesExist = Temp1.exists();
              System.out.println(fullyQualifiedFileName);
              System.out.println("Does "+ fullyQualifiedFileName +" Exist? -"+doesExist);
    The path prints correctly, the file does exist at the location give, the filename is correct but for some reason it returns false. Any ideas?
    Dave

    Does the user have access rights to the file?

  • File.exists()  returs false even the file is present in the specified path

    Hi,
    When i try to run the following program which checks whether the file exists in the given path or not
    public class FileCheck {
    public static void main(String[] a){
    String str = a[0];
    File f = new File(str);
    if(f.exists())
    System.out.println("File Exists ");
              else
         System.out.println("File does not Exists ");
    So on solaris 10(korean) we have file named in korean language under "usr" directory. When i try to run the above program on solaris 10(Korean) using the default jre (1.5)with the parameter "/usr/file name in korean language" .The output of the program is "File Exists"
    And when i run the same class file using the jre (1.6) which is installed in our application which is an english version with the same parameter ""/usr/file name in korean language"
    The output of the program is "File does not exists".
    And this problem is only with the files which contain the name in korean language.
    So do we need to set any properties for the jre in our application to work for files which are named in korean language. Any help will be highly appreciated.
    Thanks,
    GPK
    Edited by: gpk_04 on Nov 11, 2008 1:46 PM
    Edited by: gpk_04 on Nov 11, 2008 1:57 PM

    My guess is that Java 5 and 6 are picking up the file system encoding differently. As a consequence, the JVM is either:
    1. reading and converting your command line argument incorrectly, or
    2. reading and converting the file name from the file system incorrectly.
    Write a quicky, short app that prints out the file encoding of your host. Run this under 5 and then 6. Do you see different outputs?

  • Reasons File.Delete returning false

    Hi,
    I always assumed that if file.delete did not delete a file, it would raise an exception - however, today I have found out otherwise.
    What are some of the reasons why File.delete would return false (without throwing an exception). I've haven't seen the results of a chmod (which I am waiting on, but I have been assured they are set correctly - besides, I can delete files on the server directory through an Explorer on my Client PC.
    Thanks,
    Red.

    Thanks,
    It actually turned about to be an Oracle based setting (in ora.init) which was causing the problem.
    Of your answers -
    1. I believe would return a permission exception.
    2. It would think would raise an acess exception
    3. Should return false
    4. Would likely raise an exception
    Although I could be wrong...
    Thanks again,
    Red

  • File.execute() not working for bat file

    Dear all,
    The purpose of my function copyToWinClipboard (text) is to get a string directly into the Windows Clipboard. The purpose is to allow the user of my project just to paste into the open-dialog of the application EndNote. I’m not certain whether the FM clipboard (supported by the copy/cut/paste methods for Doc) really fills into the Windows Clipboard also.
    In the PhotoShop script forum I found the idea how to do this.
    #target framemaker
    // note the blank in the path
    copyToWinClipboard ("E:\\_DDDprojects\\FM+EN escript\\FM-11-testfiles\\BibFM-collected.rtf");
    function copyToWinClipboard (text) {
      var theCmd, clipFile = new File(Folder.temp + "\\ClipBoardW.bat");
      clipFile.open('w');
    //  theCmd = "echo \"" + text + "\" | clip"; // this doesn’t help either
      theCmd = "echo " + text + " | clip";
      clipFile.writeln (theCmd);
      clipFile.close ();
      clipFile.execute ();
    Running this script provides a short flicker (the command prompt), but the clipboard does not contain the expected string. However, when double clicking on the generated I:\!_temp\ClipBoardW.bat the clipboard is filled correctly.
    IMHO the execute method does not work correctly for bat files. In another area of my project-script i run an exe file with this method correctly.

    Hi Klaus,
    sorry for my late response.
    execute definitely works witch batch-files
    Here's a "batch" - example you can test.
    There are two methods to prevent window from closing:
    "|more" - kind of pagebreak
    "pause"
    var oTemp = app.UserSettingsDir + "\\tmp";
        var MyDosCommand = "ipconfig.exe /a|more";
        var MyPath = new Folder (oTemp);
        if (!oTemp.exists)
            var MyPath = new Folder (oTemp);
            var lFehler = MyPath.create();
        oTemp = oTemp + "\\" +"nw.bat";
        var MyFile = new File (oTemp);
             MyFile.open ('w');
               if (MyFile.error > "")
                    alert("ERROR");
            MyFile.writeln(MyDosCommand);
            MyFile.writeln("pause");
            MyFile.close();
            MyFile.execute();

  • File Adapter Fault Handling for CSV files

    I have been working on a requirement where the file adapter picks up the file and gives to the BPEL for processing the data.
    In my composite, i have configured the file adapter as a service for reading files, and i defined the xsd using the native format builder....
    <?xml version="1.0" encoding="UTF-8" ?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:nxsd="http://xmlns.oracle.com/pcbpel/nxsd"
    xmlns:tns="http://TargetNamespace.com/ReadFile"
    targetNamespace="http://TargetNamespace.com/ReadFile"
    elementFormDefault="qualified"
    attributeFormDefault="unqualified"
    nxsd:version="NXSD"
    nxsd:stream="chars"
    nxsd:encoding="US-ASCII"
    nxsd:hasHeader="true"
    nxsd:headerLines="1"
    nxsd:headerLinesTerminatedBy="${eol}"
    >
    <xsd:element name="Root-Element">
    <xsd:complexType>
    <xsd:sequence>
    <xsd:element name="Student" minOccurs="1" maxOccurs="unbounded">
    <xsd:complexType>
    <xsd:sequence>
    <xsd:element name="Name" type="xsd:string" nxsd:style="terminated" nxsd:terminatedBy="," nxsd:quotedBy="&quot;" />
    <xsd:element name="Street1" type="xsd:string" nxsd:style="terminated" nxsd:terminatedBy="," nxsd:quotedBy="&quot;" />
    <xsd:element name="Street2" type="xsd:string" nxsd:style="terminated" nxsd:terminatedBy="," nxsd:quotedBy="&quot;" />
    <xsd:element name="City" type="xsd:string" nxsd:style="terminated" nxsd:terminatedBy="," nxsd:quotedBy="&quot;" />
    <xsd:element name="State" type="xsd:string" nxsd:style="terminated" nxsd:terminatedBy="," nxsd:quotedBy="&quot;" />
    <xsd:element name="Country" type="xsd:string" nxsd:style="terminated" nxsd:terminatedBy="${eol}" nxsd:quotedBy="&quot;" />
    </xsd:sequence>
    </xsd:complexType>
    </xsd:element>
    </xsd:sequence>
    </xsd:complexType>
    </xsd:element>
    </xsd:schema>
    If i put some test data like below , the .txt file is being picked up and the valid being passed to the BPEL and its not returning any error for the invalid records. In this case, just want to throw an error and exit the bpel.
    Krish,abcd,abcd,chennai,tnin - comma is missing here
    NP,abcd,abcd,chennai,tnin - - comma is missing here
    Nutan,abcd,abcd,chennai,tn,in - this record being processed successfully.
    Pari,abcd,abcd,chennai,tn,in - - this record being processed successfully.
    Experts, any help is really appreciated..

    Hi,
    its better to opt for seeburger for EDI data processings..
    http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/20ed5d5b-b188-2c10-76a2-997a616e48a9
    http://www.cbs-consulting.com/EN/Services/ProcessesApplications/SAP__TechnologyConsulting/OpenPI/OpenPI__n,naviExpand=.html__nnn=true
    Check the above links can be helpful..
    HTH
    Rajesh

  • Sharepoint Online - File Associations - Create association for .sql files in SPO365

    I maintain a document library as a script repository with .sql scripts.  we refer to these often for operational processes.  
    unfortunately, we are currently only given the option to download these files from SharePoint Online.   
    Is it possible to create an association in SharePoint Online to have these files preview as text or to at least open them in SSMS or Notepad. 
    caveat =  we dont want to change the default OS association for these files.  SSMS is fine for the desktop, but in SPO365 a text viewer would be ideal as it would most easlily facilitate a copy and paste. 
    Thanks 
    G'B
    Scott Davis

    Hi,
    According to your description, when you removed the Read List and Read Item operations and created them back based off of the view and recreated the external list, you saw all the columns you wanted.
    Then you can modify view to choose the columns which you want to display.
    The issue is, now the item picker and other operations that did not change seem to be going off of the view.
    Do you mean that when you add/edit the item, it still displays the foreign key column in the list view?
    Best Regards,
    Lisa Chen
    Forum Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
    [email protected]
    Lisa Chen
    TechNet Community Support

  • How can we call a class file of one package for class file of another

    How can we call a class file of one package from class file of another package and both packages exist in a same folder

    How can we call a class file of one package from
    class file of another package and both packages exist
    in a same folder
    Luckily they don't so it's really not a problem after all.

  • File Adapter: Advanced selection for source file

    Hi Experts,
    I am doing file(Idoc format) to IDoc scenario. In my scenario I am getting files in three different formats (ex: abc.dat, xyz.dat, 123.edi). My communication channel (sender file adapter) should poll for every 30 mins, picks up the files and map them to Idoc without any mapping.
    Need following clarifications:
         1. Should I create 3 communication channels to pick up 3 different type files? Or should I use the Advanced selection for source file to pick up them with only one CC?
         2. If there is no mapping how should I proceed in this case?
    Regards,
    Rams

    >>1. Should I create 3 communication channels to pick up 3 different type files? Or should I use the Advanced selection for source file to pick up them with only one CC?
    Not required.. if all the files are from the same directory then u can specify .  in the file name parameter.. but make sure that only these 3 file types are places in the directory... if this is not the case you can use Advannced Selection... check my Wiki [Single Sender File CC For Multiple Directories|https://wiki.sdn.sap.com/wiki/display/XI/SingleSenderFileCCForMultipleDirectories]
    >>2. If there is no mapping how should I proceed in this case?
    Mappiing is required only if the source and the target structure are different.. if u send the file with the IDocc XML format mapping is not required...
    ~SaNv....

Maybe you are looking for

  • Blank screen after reboot - M30-70

    Hi @ All, I have received 5 Lenevo M30-70's last week (1st April 2015) - all brand new in the box (with Windows 7 x64 Professional pre-installed as the OS).  I've successfully setup one laptop with all of our standard applications within our domain -

  • I can no longer find a manage bookmarks tab anywhere in my (the latest) Firefox browser.

    I have been using browsers for over 15 years, and Firefox for about 10. After the next to last Firefox upgrade I was no longer able to find a manage bookmarks tab. I can bookmark a page and place it in an existing folder, but I can no longer create f

  • How to create CRM only Sales Organisation?

    Hello all, We have downloaded our org model from R/3. We want to extend our org model in CRM with a sales organisation which does not exist in R/3. This should be possible as CRM can run stand alone but we cannot figure out how. Does anybody have any

  • The class of the deferred-methods return type "{0}" can not be found.

    I am developing a multilingual portal application. I have the method that changes the locale based on user's choice in the bean and the method is being referred to as below. <af:selectOneChoice label="Select Language" autoSubmit="true" value="#{local

  • DIablo II and MBP

    Hey all, not sure where else to post this question. Hope it's appropriate to the board. So, I had a 'universal' copy of Diablo II for my PC - just got my MBP in April - and installed it and downloaded the MacOSX patch from the Diablo II website. When