Directory properties in java.io.*

I know I can check if a directory exists with the .exists method, but I want to know if the directory contains anything. Is there any built-in method for this? If a built-in method doesn't exist, I'm thinking that I would have to use the .length of the filelisting method, but would it work?

If a built-in method doesn't exist, I'm
thinking that I would have to use the .length of the
filelisting method, but would it work?You could always try it and find out.

Similar Messages

  • How to avoid directory listing in java web applications.

    how to avoid directory listing in java web applications.
    That is on typing the url of the application it should not the directory listing. Welcome tag in web.xml doesnot fully solve the problem, since still the images folder etc is still accessible

    I know of two ways.
    If you're using tomcat and have access to the conf directory.
    Edit your $TOMCAT/conf/web.xml. Find your default servlet properties and change
      <servlet>
        <servlet-name>default</servlet-name>
        <servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
        <init-param>
          <param-name>debug</param-name>
          <param-value>0</param-value>
        </init-param>
        <init-param>
          <param-name>listings</param-name>
          <param-value>true</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
      </servlet>to  <servlet>
        <servlet-name>default</servlet-name>
        <servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
        <init-param>
          <param-name>debug</param-name>
          <param-value>0</param-value>
        </init-param>
        <init-param>
          <param-name>listings</param-name>
          <param-value>false</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
      </servlet>And restart your server. This will affect every directory on the server, and return a 405 directory browsing forbidden error.
    Another way, is to place an index.jsp inside each directory with a simple one line redirect to your applications CONTEXT_PATH.response.sendRedirect("http://yourserver/yourapp/");This will only affect specific directories which contain these index.jsp files.
    Hope this helps

  • Finding the directory path in java

    I need to check if a file exists or not before an action is taken. I used File class to get the handle of a file and and then used exist() function to check if it is there. But this function needs to full path to that file. I need to find a directory path at runtime as the application is deployed in different environment and wouldn't know the directory path in each environment. Could somebody help me on this. Thanks,

    fBut this function
    needs to full path to that file. I need to find a
    directory path at runtime as the application is
    deployed in different environment and wouldn't know
    the directory path in each environment. Well, that can only you know where this file is on the different platforms. So maybee you can provide it as a user-input, a parameter to the program or be set in a settings-file which the program reads.
    If you want the full path to the current directory where the java program runs, this works:
    File f=...;
    String absPath=f.getAbsolutePath();
    File absPathFile=new File(absPath);Gil

  • How to use directory alias in Java stored procedure ?

    hi everyone !
    I want use Directory alias in Java strored procedure
    I 'hv created dir alias as
    Create Directory BFILE_DIR AS 'C:\MyImages'
    my java statements -
    myfile="C:\MyImages\myPH01.jpg"
    File binaryFile = new File(myFile);
    instead of giving absolute path I want give directory alias BFILE_DIR
    myfile= BFILE_DIR + "myPH01.jpg"
    File binaryFile = new File(myFile);
    can anyone pl suugest how should I write this in Java procedure
    thanks
    SPD

    hi everyone !
    I want use Directory alias in Java strored procedure
    I 'hv created dir alias as
    Create Directory BFILE_DIR AS 'C:\MyImages'
    my java statements -
    myfile="C:\MyImages\myPH01.jpg"
    File binaryFile = new File(myFile);
    instead of giving absolute path I want give directory alias BFILE_DIR
    myfile= BFILE_DIR + "myPH01.jpg"
    File binaryFile = new File(myFile);
    can anyone pl suugest how should I write this in Java procedure
    thanks
    SPD

  • Directory monitor in Java, help

    Hey everyone,
    I'm attempting to write a directory monitor in java but I'm stuck. I'm trying to find something in Java that is like FileSystemWatcher in .NET but I don't think java does. From what I read is that you have to continually poll the directory for changes. What I would like to know is that are there any events and/or signals raised when a changes are made so that one could catch and process them? If not, could someone explain how to simply poll the directory for changes?
    Thanks
    Barefoot

    barefootsanders wrote:
    This is exactly what I need to do. Now, i already have been working on the last modified time comparison which is relatively simple. What I was stuck on was finding what was different between the two file lists. Would I have to iterate through the entirety of the list and compare each item to find what was different or is there a more efficient way of doing this?The simplest thing to do would be to use Collection's removeAll method to get the difference between the two. This will show you which files have been added (using newList.removeAll(oldList)) and which have been removed (using oldList.removeAll(newList)).
    A few notes:
    * removeAll modifies the collection on which you call it, so you'll need to make copies.
    * File's equals method docs say: Returns true if and only if the argument is not null and is an abstract pathname that denotes the same file or directory as this abstract pathname. Whether or not two abstract pathnames are equal depends upon the underlying system. On UNIX systems, alphabetic case is significant in comparing pathnames; on Microsoft Windows systems it is not.
    So you'll need to decide if that's good enough, or if you want to implement your own comparison for files. Also, it's not clear from the above how shortcuts or symbolic links are handled--whether the shortcut and the original are considered equal or not.
    * Based on the above, you may get different results with a List vs. a Set, so play around and see which one better suits your needs.
    * I think a directory's mod time only changes if you add or remove or rename files, or explicitly change it, as with the touch command in unix. I don't think modifying the contents of an existing directory cause that directory's mod time to be updated. If you want to know when a file has changed, you'll probably have to poll that file's mod time explicitly.
    In light of the above, I suggest you start by writing a small program that does nothing but poll a directory every, say, 5 or 10 or 30 seconds and print out whether it's changed or not. Then, while that program is running, do various things like add, delete, rename, rename with same letters but different case, etc. and see if the program gives you the results you want. If not, you'll have to tweak it based on your findings.

  • Copying complete directory structure using java.io.File

    Is there a solution to problem when you want to copy a complete directory structure using java.io.File class as you can copy when using FTP connection.

    Is there a solution to problem when you want to copy
    a complete directory structure using java.io.File
    class as you can copy when using FTP connection.FTP does not have a command to transfer all the files in a directory. FTP clients implement this by invoking single file transfer for each file in a directory.

  • Reply to client by setting properties of java.rmi

    Hi All,
    I am very new to JAVA RMI.
    Is it possible for me to send a reply to client by setting the properties of java.rmi ?. I mean the reply string , if i am returning a string to client program ?.
    Shammi

    I will be more specific.
    What I meant by properties is system properties applied to the classes in java.rmi.* which we can set. For example,
    System.setProperty("java.rmi.server.codebase", "file://home/shammi/test");
    For the second portion, for example, if my server returns the string "Hello World" to the client, I will have a server method some what similar to the one given below
    public String SayHello()     {
              return "Hello World\n";
    Is it possible for me to do this in another way rather than explicitly specifying the return string.
    Shammi

  • IView Properties in Java

    Hi,
       Is it possible to set iView Personalization properties from Java? I am writing a JSPDynpage to display some content and want to put a button on this page e.g."Remove"
    this should trigger/set the "Remove iView" for that user.
    I am able to read the property but want to know how to set.
    request.getComponentContext().getProfile().getProperty("com.sap.portal.iview.ShowRemove")[
    this is just displaing true or false whether to show this property in personalization or not.
    We disabled personalization option for all users,but need this feature for one iView.
    Thanks
    Tegala

    Hi,
    The issue seems not to be with the Show Remove property -- this only indicates to the portal whether to display this option to the user.
    You seem to be asking how do I actually remove the iView from the page, no?
    If so, you query the PCD for the page you want, get from the page the IiView object of the iView you want to hide, and then change the avilability property.
    Here is some sample code to do this:
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY, IPcdContext.PCD_INITIAL_CONTEXT_FACTORY);
    env.put(Constants.REQUESTED_ASPECT, PcmConstants.ASPECT_SEMANTICS);
    env.put(Context.SECURITY_PRINCIPAL, request.getUser());
    env.put(IPcdContext.PCD_PERSONALIZATION_PRINCIPAL, request.getUser());
    InitialContext iCtx = null;
    String pageID = "portal_content/DanielContent/DanRole/Folder1/Folder2/Page1";
    try {
      iCtx = new InitialContext(env);
      IPage myPage = (IPage)iCtx.lookup(pageID);
      Enumeration myIviews = myPage.getiViews();
      while (myIviews.hasMoreElements()) {
         Binding bind = (Binding) myIviews.nextElement();
         IiView myIview  = (IiView) bind.getObject();
         myIview.putAttribute(IAttriView.ATTRIBUTE_AVAILABILITY,IAttriViewValues.AVAILABILITY_VALUE_AVAILABLE);
         myIview.save();     
    I think the casting to a Binding object can be skipped, and you can cast directly to an iView. This is adapted from another code sample where you wanted to distinguish if the object was an iView or a page and then cast it.
    Hope this helps.
    Daniel

  • Using Directory alias in Java stored procedure

    hi !!
    I want use Directory alias in Java strored procedure
    I 'hv created dir alias as
    Create Directory BFILE_DIR AS 'C:\MyImages'
    my java statements -
    myfile="C:\MyImages\myPH01.jpg"
    File binaryFile = new File(myFile);
    instead of giving absolute path I want give directory alias BFILE_DIR
    myfile= BFILE_DIR + "myPH01.jpg"
    can anyone pl suugest how should I write this in Java procedure
    thanks
    SPD

    Hi there i am currently trying to develope a java
    stored procedure and place it in oracle and will try
    to use that procedure to send a message to a server
    but then it doesnt seems to work. is it possible?And what do you do with exceptions in your java proc?
    I haven't ever done it myself, but I would be very surprised if it wasn't possible. I also wouldn't be surprised to find out that you have to configure various things to allow it in Oracle itself.

  • Add a posixaccount user in posixgroup in sun directory server using java

    Hi
    Anybody now how to add posixaccount user in posixgroup in sun directory server using java code.
    I am able to add normal directory server user in ldap group in java.
    But i am getting any luck to add posixaccount user in posixgroup.
    I know we can set uid value in memberuid attribute but how to add through java program.
    Anybody can paste code for that.
    Thanks.

    To CRabel,
    My company have restriction on using the open sources product/code, but i will take a look on netscape ldap sdk as a reference~
    To raghu1978 ,
    i find a product call Directory Editor 1 2005Q1, I hope it is useful.
    thz all~

  • Configure TCP/IP system properties with java

    I'm looking to do is to be able to set my TCP/IP properties using java every time I switch physical networks so that it is configured properly. One network automatically gives an IP while the other requires a static one. I'd rather not have to keep typing it in everytime so I'm looking for a way to automatically change it.
    I'm thinking that the route to go would be through the java.lang.system to get the system properites but that'll only get me the os name and version stuff.
    Any ideas?

    I believe this will require native functionality. Each OS handles the specification of TCP/IP information differently. Getting the system properties is not going to help. The only way I can imagine doing this is to create a set of Java classes which provide a platform-independent abstraction for changing TCP/IP information and then use JNI to implement the natvie code for each platform you want to support.
    Jitender - [email protected]

  • Need to change the directory using the java program

    hi,
    can anyone give me the code to change the directory in the java program by using the system command.
    as in C where we use the system call system("cd");
    the same way how to do that in java. please help me with that!!!

    Please search the forums for "runtime.exec", there are dozens of examples posted.
    Although this may not do you any good, since changing the os's directory is not likely to change anything you're using in Java. What are you trying to do?

  • Error: Could not read reports properties.  java.lang.NullPointerException

    Hi All,
    I am facing Could not read reports properties. java.lang.NullPointerException while trying to run the report using below string
    String:_
    /rcrmap2/weblogic/bea/ORA_PFRD/bin/rwrun module=/rcrmkr1/exe_dir/CA_PG1_T.rdf CUSTGRPID=''001139'' CANO=104 CACOPY=''F'' OPTION=''W'' CCODE=''KR'' USERID=apl_D_RCRMNIU3/Q5e3C4l1FPjrG6epG6f3C4dqFMgsDP@krcrmd DESTYPE=FILE DESNAME=/rcrmkr1/crms_RG/rep_dir/gcapg1_to_test_20110112_121902.rep BATCH=YES MODE=CHARACTER DESFORMAT=/rcrmap2/weblogic/bea/ORA_PFRD/reports/printers/wide.prt pagesize=132x80
    Environment Variables :*
    export ORACLE_LOCALPREFERENCE=/rcrmap2/weblogic/bea/rcrms/config/FRComponent/frcommon/tools/admin/
    export WIDE_DEF=/rcrmap2/weblogic/bea/ORA_PFRD/reports/printers/hplwide.prt
    export WIDE_VIW=/rcrmap2/weblogic/bea/ORA_PFRD/reports/printers/wide.prt
    export REPORTS_FONT_DIRECTORY=/rcrmap2/weblogic/bea/rcrms/reports/fonts
    export REPORTS_TAGLIB_URI=/WEB-INF/lib/reports_tld.jar
    export REPORTS_NO_DUMMY_PRINTER=TRUE
    export REPORTS_TMP=/tmp
    export RW=/rcrmap2/weblogic/bea/ORA_PFRD/reports
    export LD_LIBRARY_PATH=/rcrmap2/weblogic/bea/ORA_PFRD/jdk/jre/lib/ppc64:/rcrmap2/weblogic/bea/ORA_PFRD/jdk/jre/lib/ppc64/classic:/rcrmap2/weblogic/bea/ORA_PFRD/lib:/usr/dt/lib:
    export LIBPATH=/rcrmap2/weblogic/bea/ORA_PFRD/lib:/usr/dt/lib:/rcrmap2/weblogic/bea/ORA_PFRD/jdk/jre/lib/ppc64:/rcrmap2/weblogic/bea/ORA_PFRD/jdk/jre/lib/ppc64/classic:/usr/lpp/cobol/lib:/oracle/oracle/11.1.0.7/lib:/oracle/oracle/11.1.0.7/lib32:/rcrmkr1/exe_dir/pvcs_12july/pco:.
    export LDR_CNTRL=USERREGS@MAXDATA=0x80000000
    export TK_ICON=/rcrmap2/weblogic/bea/ORA_PFRD/reports/plugins/resource
    export REPORTS_DEFAULT_DISPLAY=NO
    export REPORTS_CLASSPATH=/rcrmkr1/exe_dir:/rcrmap2/weblogic/bea/ORA_PFRD/reports/jlib/rwbuilder.jar:/rcrmap2/weblogic/bea/ORA_PFRD/reports/jlib/rwrun.jar:/rcrmap2/weblogic/bea/ORA_PFRD/jlib/zrclient.jar:/rcrmap2/weblogic/bea/ORA_PFRD/modules/oracle.jsp_11.1.1/ojsp.jar:/rcrmap2/weblogic/bea/ORA_PFRD/javacache/lib/cache.jar:/rcrmap2/weblogic/bea/ORA_PFRD/modules/oracle.javacache_11.1.1/cache.jar
    Please help to provide your inputs
    Regards,
    Harish

    Hi,
    The problem was resolved by setting proper acl's to the corresponding directories (cache directory) in the application server
    Regards,
    Harish

  • Retrieving user data from Directory Server using java code

    Can anyone send java code to bind to directory server and retrieve the user information from server instance.

    To CRabel,
    My company have restriction on using the open sources product/code, but i will take a look on netscape ldap sdk as a reference~
    To raghu1978 ,
    i find a product call Directory Editor 1 2005Q1, I hope it is useful.
    thz all~

  • Can't load runtime properties in java.util.logging.LogManager

    This should be so easy, what am I doing wrong?
    I have the following logging.properties located on my classpath:
    handlers=java.util.logging.ConsoleHandler
    .level=INFO
    java.util.logging.ConsoleHandler.level=INFO
    java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter
    Test.level=FINE
    Test.handlers=java.util.logging.ConsoleHandlerI have a very simple Test.java file that should load the new properties file and print out the known logger names (ie Test).
    I've also tried putting Test.java in a package, it didn't seem to matter.
    public class Test {
      public Test() {
        String name = this.getClass().getName();
        //this properties file is should be sitting in same dir as Test class
        java.io.InputStream is = this.getClass().getResourceAsStream("logging.properties");
        try {
          //get log manager instance
          java.util.logging.LogManager lm = java.util.logging.LogManager.getLogManager();
          //read the new configuration
          lm.readConfiguration(is);
          //print out list of logger names
          java.util.Enumeration e = lm.getLoggerNames();
          while (e.hasMoreElements()) {
            System.out.println(e.nextElement());
          //print logger for this class!
          System.out.println("getLogger("+name+"): "+lm.getLogger(name));
        } catch (Exception e) {
        } finally {
          try {
            is.close();
            is = null;
          } catch (Exception e) {}
      public static void main(String[] args) {
        Test test1 = new Test();
    }The output I get from this is a single logger name, and then null for my desired Test logger.
    global
    getLogger(Test): null

    It seems a logger instance HAS been created for my Test class, I've added the lines below. Though it didn't appear in the logger names enumeration.
    java.util.logging.Logger logger = java.util.logging.Logger.getLogger(name);
    System.out.println(logger.getName()+"="+logger.getLevel().getName());
    logger.severe("severe");
    logger.warning("warning");
    logger.info("info");
    logger.config("config");
    logger.fine("fine");
    logger.finer("finer");
    logger.finest("finest");Output:Test=FINEST
    6/10/2003 16:00:01 Test <init>
    SEVERE: severe
    6/10/2003 16:00:01 Test <init>
    WARNING: warning
    6/10/2003 16:00:01 Test <init>
    INFO: infoObservations:
    1) Despite my Test class having the FINEST log level, the default ConsoleHandler had log level of INFO, and hence only up to INFO logged.

Maybe you are looking for

  • FBL5N transaction - URGENT

    Hi all, Currently, I am developing a report to show all open items (like transaction FBL5N, Open Item at Key Date). Now, my report just manage to display all open items as per selected key date, but not manage to show those items that were cleared. e

  • Everytime I try to download itunes it says, Itunes Installer Interrupted?!

    I was originally having problems downloading itunes because I couldn't get Quicktime and Itunes off my computer, but I download a program called Byetunes that completely deleted itunes from my computer. Unfortunately now every time it gets finish dow

  • Listing Items based on criteria e.g. High Priority Items First.

    Hi, One of our customers have a need to List High Priority Items first on the WebTools site. Let's take two ItemCodes for example: Printer001, and, Monitor001. >> If these two items are included in the same category then Monitor001 will appear before

  • Restoring iTunes from a backup hard drive

    OK so my hard drive crashed. The good news is that the backup drive has all of my music on it. I got a new hard drive and installed iTunes. But now I do not understand how to get the music and playlists off of my backup drive and on to my new drive?

  • CS6 can't open Raw Nikon D4 files

    I cannot open Raw files from my Nikon D4 in CS6 beta but I can in CS5 as it updated Camera Raw recently for it to work with the D4. Can I update CS6 for it to open Nikon D4 Raw files ?