2 Replies Latest reply: Jun 11, 2008 4:00 AM by 611760 RSS

    extract files from a folder

    807591
      hello..
      so...i have a folder in which i have 35 000 txt files..
      i have to create a class which goes through that folder and gets me the files one by one...and the class' method must return me a txt file...and each time i call it from another method...it has to get me another file...hoe do i do that?
      i found something in java.io.file but i think it uses constructor...and i kind of new in java so i don't really understand that..
      cand you hepl me please...
      conclusion:
      i have to return a distinct txt file from that folder every time that method is called..
        • 1. Re: extract files from a folder
          800282
          darky wrote:
          hello..
          so...i have a folder in which i have 35 000 txt files..
          i have to create a class which goes through that folder and gets me the files one by one...and the class' method must return me a txt file...and each time i call it from another method...it has to get me another file...hoe do i do that?
          i found something in java.io.file but i think it uses constructor...and i kind of new in java so i don't really understand that..
          cand you hepl me please...
          conclusion:
          i have to return a distinct txt file from that folder every time that method is called..
          In your class:
          - read all files from that directory using File's listFiles() method.
          - put all the files you're intersted in on a java.util.Stack
          - each time a file is requested, pop it from the stack

          And please don't ask for "sample codes", I don't have any. Try it yourself first, and when you get stuck, ask a specific question about YOUR code here on the forum.

          Good luck.
          • 2. Re: extract files from a folder
            611760
            Is it likely that any files will be added or removed from the directory whilst you are processing?