Results 1 to 8 of 8
  1. #1
    krishna523 is offline Member
    Join Date
    Jul 2011
    Posts
    6
    Rep Power
    0

    Thumbs up File created/Directory changed Events in java

    Hi All,

    This is krishna new to Java .

    My task is To create a 100 files in a directory . Initially Directory is empty , when ever a file is created or Directory

    changes (means New file is created) An event to be occur which will call some other action to be implemented.

    Thank you,
    krishna

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  3. #3
    krishna523 is offline Member
    Join Date
    Jul 2011
    Posts
    6
    Rep Power
    0

    Default

    Thanks for Reply

    What i want exactly is ,In java I created 100 files using files concept. like file1,file2,......file100

    in some directory say "c:/krishna".

    Now My question is while running my program (creation of files) i want to see if directory is changed i want to

    perform some action .is there any events like directory or folder changed events in java.

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    You have several option for that.

    1. You can simple deals with the file count in that folder. But you have to do it periodically.

    2. (this is what I suggest you) If all the files are created from your own applications you must have a notion about the file creating one by one. So perform your action within that level.

  5. #5
    krishna523 is offline Member
    Join Date
    Jul 2011
    Posts
    6
    Rep Power
    0

    Default

    Thanks for ur time,

    Is there any idea like By using Events in java.

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,728
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by krishna523 View Post
    Now My question is while running my program (creation of files) i want to see if directory is changed i want to
    perform some action .is there any events like directory or folder changed events in java.
    Java 7 has that functionality; it has a Watch Service that can notify you whenever there is a change in a directory; Java 6 and below don't have it and you should implement it yourself by periodically scannnng the entire directory for changes. This approach doesn't scale well though ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  8. #8
    krishna523 is offline Member
    Join Date
    Jul 2011
    Posts
    6
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    Event sense what you want to do once a new file is created in that folder?
    I want the file or file path to be passed as argument to another function

Similar Threads

  1. running the created jar file
    By Mostafa_mech in forum NetBeans
    Replies: 12
    Last Post: 07-02-2010, 12:06 PM
  2. Replies: 5
    Last Post: 11-22-2009, 05:48 PM
  3. Replies: 1
    Last Post: 11-03-2009, 08:07 AM
  4. Replies: 1
    Last Post: 04-01-2009, 08:34 PM
  5. How to find file created date.....
    By roshithmca in forum Advanced Java
    Replies: 1
    Last Post: 02-18-2008, 10:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •