Topic
  • 8 replies
  • Latest Post - ‏2010-12-29T01:59:47Z by Molly.Mazar
aryan_raj
aryan_raj
9 Posts

Pinned topic file exists problem

‏2010-07-11T21:26:00Z |
Hi all,

I am facing a strange problem using java.io.File exists. I am using RAD V7.5, I wrote a simple java class with main method to test whether a file exists or not using the File.exists operation. When I run this program it is giving expected result. But when I use the same code and run it on a WebSphere Portal server it always says that the file doesn't exist even when the file is there.
Updated on 2010-12-29T01:59:47Z at 2010-12-29T01:59:47Z by Molly.Mazar
  • Caleb_Payne
    Caleb_Payne
    9 Posts

    Re: file exists problem

    ‏2010-08-05T23:08:31Z  
    > aryan_raj wrote:
    > Hi all,
    >
    > I am facing a strange problem using java.io.File exists. I am using RAD V7.5, I wrote a simple java class with main method to test whether a file exists or not using the File.exists operation. When I run this program it is giving expected result. But when I use the same code and run it on a WebSphere Portal server it always says that the file doesn't exist even when the file is there.

    Are you using an absolute path or a relative path? If you're using a relative path, that's probably the problem.
    Example:
    
    
    
    if(File.exists(
    "my_file.txt")) 
    { ... 
    } 
    // <-- relative 
    // instead of 
    
    if(File.exists(
    "/full/path/to/my_file.txt")) 
    { ... 
    }
    
  • aryan_raj
    aryan_raj
    9 Posts

    Re: file exists problem

    ‏2010-08-06T20:17:34Z  
    > aryan_raj wrote:
    > Hi all,
    >
    > I am facing a strange problem using java.io.File exists. I am using RAD V7.5, I wrote a simple java class with main method to test whether a file exists or not using the File.exists operation. When I run this program it is giving expected result. But when I use the same code and run it on a WebSphere Portal server it always says that the file doesn't exist even when the file is there.

    Are you using an absolute path or a relative path? If you're using a relative path, that's probably the problem.
    Example:
    <pre class="jive-pre"> if(File.exists( "my_file.txt")) { ... } // <-- relative // instead of if(File.exists( "/full/path/to/my_file.txt")) { ... } </pre>
    I am using the absolute path, but the path used is not local, the file is residing on remote machine. And I have permissions/access to that file.
  • Caleb_Payne
    Caleb_Payne
    9 Posts

    Re: file exists problem

    ‏2010-08-07T02:11:07Z  
    • aryan_raj
    • ‏2010-08-06T20:17:34Z
    I am using the absolute path, but the path used is not local, the file is residing on remote machine. And I have permissions/access to that file.
    > aryan_raj wrote:
    > I am using the absolute path, but the path used is not local, the file is residing on remote machine. And I have permissions/access to that file.

    Could you possibly post a code snippet to provide a little more context?

    Other suggestions:
    You say that you have permissions to view the file, but does the process owner that's running the portal server have the proper permissions to view/access the file?

    Without actually seeing the code snippet in question, these are basically shots in the dark. Perhaps you could post an SSCCE like the demo you used that calles File.exist in main()?
  • aryan_raj
    aryan_raj
    9 Posts

    Re: file exists problem

    ‏2010-08-07T18:55:56Z  
    > aryan_raj wrote:
    > I am using the absolute path, but the path used is not local, the file is residing on remote machine. And I have permissions/access to that file.

    Could you possibly post a code snippet to provide a little more context?

    Other suggestions:
    You say that you have permissions to view the file, but does the process owner that's running the portal server have the proper permissions to view/access the file?

    Without actually seeing the code snippet in question, these are basically shots in the dark. Perhaps you could post an SSCCE like the demo you used that calles File.exist in main()?
    
    path=
    "\\\\<hostname>\\<folder>\\<filename>"; File f = 
    
    new File(path); System.out.println(
    "===file exists--"+f.exists());
    
  • Caleb_Payne
    Caleb_Payne
    9 Posts

    Re: file exists problem

    ‏2010-08-07T19:20:52Z  
    • aryan_raj
    • ‏2010-08-07T18:55:56Z
    <pre class="jive-pre"> path= "\\\\<hostname>\\<folder>\\<filename>"; File f = new File(path); System.out.println( "===file exists--"+f.exists()); </pre>
    > aryan_raj wrote:
    >
    
    path=
    "\\\\<hostname>\\<folder>\\<filename>"; > File f = 
    
    new File(path); > System.out.println(
    "===file exists--"+f.exists()); >
    


    That seems pretty straight-forward to me :/
    It also looks like a windows path and - to be perfectly honest with you - I've used windows only a handful of times in the past 10 years.
    Out of curiosity - is it throwing an exception or simply just returning false?
  • aryan_raj
    aryan_raj
    9 Posts

    Re: file exists problem

    ‏2010-08-09T13:27:52Z  
    > aryan_raj wrote:
    > <pre class="jive-pre"> path= "\\\\<hostname>\\<folder>\\<filename>"; > File f = new File(path); > System.out.println( "===file exists--"+f.exists()); > </pre>

    That seems pretty straight-forward to me :/
    It also looks like a windows path and - to be perfectly honest with you - I've used windows only a handful of times in the past 10 years.
    Out of curiosity - is it throwing an exception or simply just returning false?
    It is just returning false, but the same code works good in a simple java class with main method.
  • aryan_raj
    aryan_raj
    9 Posts

    Re: file exists problem

    ‏2010-08-09T13:29:09Z  
    > aryan_raj wrote:
    > <pre class="jive-pre"> path= "\\\\<hostname>\\<folder>\\<filename>"; > File f = new File(path); > System.out.println( "===file exists--"+f.exists()); > </pre>

    That seems pretty straight-forward to me :/
    It also looks like a windows path and - to be perfectly honest with you - I've used windows only a handful of times in the past 10 years.
    Out of curiosity - is it throwing an exception or simply just returning false?
    the same code doesn't work when I run it in WebSphere portal server.
  • Molly.Mazar
    Molly.Mazar
    1 Post

    Re: file exists problem

    ‏2010-12-29T01:59:47Z  
    Caleb_Payne wrote:
    > aryan_raj wrote:
    > Hi all,
    >
    > I am facing a strange problem using java.io.File exists. I am using RAD V7.5, I wrote a simple java class with main method to test whether a file exists or not using the File.exists operation. When I run this program it is giving expected result. But when I use the same code and run it on a WebSphere Portal server it always says that the file doesn't exist even when the file is there.

    Are you using an absolute path or a relative path? If you're using a relative path, that's probably the problem.
    Example:
    
    
    
    if(File.exists(
    "my_file.txt")) 
    { ... 
    } 
    // <-- relative</FONT>
    // instead of
    
    if(File.exists(
    "/full/path/to/my_file.txt")) 
    { ... 
    }
    

    It's quite useful, It is exactly what I need, I understand this part, Thanks for your instruction!