Reading a part of a file

Hello, do you know if this is possible (doesn't matter what language..):
If I have a big file which is much larger that my memory + swap space, say 20gb. Is it possible to say something like read the part from  the 1132312 byte to the 2132312 byte into memory. And than in memory having the option to do normal things like it was a normal file like reading it from the begin to then end byte by byte. Also is it possible to say something like replace the part from the 12312312 byte to the 22312312 byte with this that I have in memory?
I only know of things like read write and append but as far as I know this is only possible with small files.
Thanks in advance,
David

leeghoofd wrote:I only know of things like read write and append but as far as I know this is only possible with small files.
In C and most lower level languages, opening a file requires something in the area of 2-3 pointers.  That's it.  The file handle and what's called a "file pointer" which contains the location.  You can use open(), seek(), and read() to get where you want are read the amount you want.

Similar Messages

  • Cant read a part of  xml file using AS3

    Hi
    i can read everything from my xml file except a part that i can always get teh first items of each category (it will make more sence in a sec)
    So here is my xml
    [HTML]<?xml version="1.0" encoding="UTF-8"?>
    <flashxml>
      <second_page>
        <sp text="ss ptextj"/>
        <ss text="sptext"/>
        <clas text="clas"/>
      </second_page>
      <third_page>
        <ss>
          <category name="categor">
            <item>3333</item>
            <item>H4444</item>
            <item>etc etc etc </item>
          </category>
          <category name="security ">
            <item>SSL</item>
            <item>Hacke</item>
            <item>etc etc etc </item>
          </category>
        </ss>
        <sp>
          <category name="security a">
            <item>SSL lallalala</item>
            <item>Hacker</item>
            <item>etc etc etc </item>
          </category>
          <category name="onlin">
            <item>Hussle free</item>
            <item>Diafore</item>
            <item>etc etc 2 </item>
          </category>
        </sp>
        <classifieds>
          <category name="Best">
            <item>Additem1</item>
            <item>Additem2</item>
            <item>Additem3 </item>
          </category>
        </classifieds>
      </third_page>
    </flashxml>[/HTML]
    I am trying for each category in the xml to get the relevant items ...
    The problem is that if i try to read for e.g the second set of items for the second category of <sp> using a counter it throws a type error
    TypeError: Error #1010: A term is undefined and has no properties.
    at MethodInfo-1()
    at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at flash.net::URLLoader/flash.net:URLLoader::onComplete()
    so the following works
    var itemslist:XMLList = xml.third_page.ss.category[0].item;  (it will always display the first items of the first category for all the categories
    so for instance for sp will always return even for the second category
    <item>SSL lallalala</item>
            <item>Hacker</item>
            <item>etc etc etc </item>
    but when i am using
    var itemslist:XMLList = xml.third_page.ss.category[i].item;
    i am getting the type error above TypeError: Error #1010 .. (no idea why)
    Any help will be much appreciated
    complete code ::
    pp.buttonMode = true;
    pp.addEventListener(MouseEvent.ROLL_OVER, onButtonOver);
    pp.addEventListener(MouseEvent.CLICK, onButtonOut);
    function onButtonOver(e:MouseEvent):void
    e.currentTarget.gotoAndPlay("a");
    var xmlString:URLRequest = new URLRequest("ev.xml");
    var xmlLoader:URLLoader = new URLLoader(xmlString);
    xmlLoader.addEventListener("complete", init);
    function init(event:Event):void{
      var xDoc:XMLDocument = new XMLDocument();
      xDoc.ignoreWhite = true;
      var animalsXML:XML = XML(xmlLoader.data);
       //var list:XML = XML(xml Loader.data);
    // trace (animalsXML);  //prints the xml
      //edooooooooooooooooooooooooooooooooooo
    var  xml = XML(xmlLoader.data); 
               trace ("XML File");  
           trace ("===================");  
               trace (xml.second_page.sp.attribute("text"));   
          trace (xml.second_page.ss.attribute("text"));   
          trace (xml.second_page.clas.attribute("text"));   
      //edoooooooooooooooooooooooooooooooooooooooooooooooooooo
    // Third page ss
       var i = 0;
       var categorylist:XMLList = xml.third_page.ss.category;  
              for each (var captionElement:XML in categorylist)  
         i++;
                   trace (captionElement.attribute("name")); 
        //trace (captionElement.item);
        var itemslist:XMLList = xml.third_page.ss.category[0].item;
        for each (var captionElement:XML in itemslist)  
                    trace(captionElement);
      // trace (valueOf(captionElement.item));
    // Third page sp
       var i = 0;
       var categorylist:XMLList = xml.third_page.sp.category;  
              for each (var captionElement:XML in categorylist)  
         i++;
                   trace (captionElement.attribute("name")); 
        //trace (captionElement.item);
        var itemslist:XMLList = xml.third_page.sp.category[0].item;
        for each (var captionElement:XML in itemslist)  
                    trace(captionElement);
      // trace (valueOf(captionElement.item));
    // Third page clas
      var i = 0;
       var categorylist:XMLList = xml.third_page.classifieds.category;  
              for each (var captionElement:XML in categorylist)  
    i++;
               trace (i);
         trace (captionElement.attribute("name"));
        //   trace (captionElement.item);
      // trace (valueOf(captionElement.item));
        //var hi= captionElement.attribute("name");
    var itemslist:XMLList = xml.third_page.classifieds.category[0].item;
        for each (var captionElement:XML in itemslist)  
                    trace(captionElement);
      // trace (valueOf(captionElement.item));
      for each(var itemData:XML in animalsXML.elements()) {
    //  trace(itemData.elements().attribute("text")); //DOULEUI
    //third page
    //itemData.thirdpage.elements()[0].@patty
      xDoc.parseXML(animalsXML.toXMLString());
    // trace(xDoc.firstChild.childNodes[0]); //Riverside
      //trace(xDoc.firstChild.childNodes[0].nodeValue);
    //trace(xDoc.valueOf(.getElementsByTagName("item")[0].childNodes[0].nodeValue);
    function onButtonOut(e:MouseEvent):void
    e.currentTarget.gotoAndPlay("b");
    pb.gotoAndPlay("a");

    use
    var itemslist:XMLList = captionElement.item;
    instead of
    var itemslist:XMLList = xml.third_page.sp.category[0].item;
    that should work. You already got the category node in your captionElement variable, why not just use it instead of looking it up again in the document tree?

  • Reading specific part of a file

    Hi
    Im trying to design a java program that reads a txt file such as the one below:
    0 400 450 510 670 493 958
    1 500 560 630 5633
    2 625 676 740
    3 1000 1250 1600
    4 432
    5 2435 235 2654
    Then through a user prompt, outputs a specific number from a specific line to the user, i.e.
    Line 1
    Column 3
    Would print 450
    i have little knowledge of java, and im not sure if i need to read the whole file into arrays or i can get java just to read a specific line and column from it
    i have tried using arrays but as the txt file can be of any size it got confusing!
    Please help!
    Thanks to you all

    jverd is right.. you can use string tokenizer to seperate the columns of data via spaces.. or whatever you wanna specify. I'm seriously bored, so I wrote a working example for you that uses the data you posted
    import java.util.*;
    import java.io.*;
    // usage:
    // java Example <line> <column>
    public class Example {
         public Example(int line,int col) throws IOException {
              col++; // because StringTokenizer will also count the first number of the actual line
              // example.txt has the data you posted...
              BufferedReader b = new BufferedReader(new InputStreamReader(new FileInputStream("example.txt")));
              String s = "",data = "";
              int j;
              while ((s = b.readLine()) != null) {
                   if (Integer.parseInt(""+s.charAt(0)) == line) { // matches line
                        StringTokenizer st = new StringTokenizer(s); // separates words by space character
                        if (st.countTokens() < col) {
                             System.out.println("invalid column for line "+line+". there are only "+(st.countTokens()-1)+" columns on this line.");
                             System.exit(0);
                        // skip to the column..
                        for (j = 0;j < col;j++) data = st.nextToken();
                        System.out.println(data);
         public static void main(String[] args) {
              if (args.length < 2) System.out.println("use java Example <line> <column>");
              else try {
                   new Example(Integer.parseInt(args[0]),Integer.parseInt(args[1]));
              catch (NumberFormatException e) {
                   System.out.println("line and column need to be a number");
              catch (IOException e) {
                   e.printStackTrace();
    }

  • Writing to Muliple Parts of a File

    Writing a large scale application that involves several threads that read different parts of a file, correct their respective part, and recreate the file.
    Is it possible for each of the threads to write to different parts of the same file simultaneously?
    Speed is an issue here so any tips would be helpful thanks.

    spacecadet,
    Succinctly. No.
    Use separate physical files for each working portion of the table. It's called striping. Google it.
    Any other brilliant ideas?

  • Can i remove a particular part of a file?

    I have a file. I want to remove a particular of that file. I have that Outputstream for that particular portion. How can i do it?
    Thanks

    use the bufferedinputstream to read the part of the file and write onto the same file using bufferedoutputstream or create a new file and write onto it.... simple.

  • Reading a File by Knowing a part of the file name

    Hi Java Gurus,
    Can I copy a file to another location by knowing a part of the file name.I know the extension of the file and part of the file name.Can I copy such a file to another directory?
    Eg :
    0099999999_JAPPLIC_20090320.pdf is the file name.
    I know the file name contains 'JAPPLIC' .Can I use this clue and the extension of the file to copy the file to another directory.
    Please let me know whether it is possible or not.
    Regards,
    Rakesh.

    Hi ,
    I used the below code and I was able to solve the problem.I was able to select the files of the required extension and serach for the file names containing the text I know and use such files and move to another directory.It may be helpfulk to you people
    public class FileDeletion {
    public static void main (String args[]) {
         String e = "";
         String d = "C:\\TCCTouchpoints\\Attachments_Export\\outbound";
         String newFileLoc = "C:\\TCCTouchpoints\\Attachments_Export\\move";
    ExtensionFilter filter = new ExtensionFilter(e);
    File dir = new File(d);
    File newLoc = null;
    String[] list = dir.list(filter);
    if (list.length == 0) return;
    System.out.println("File Length "+list.length);
    ArrayList fileNames = new ArrayList();
    for (int i = 0; i < list.length; i++) {
    /*file = new File(d + list);
    boolean isdeleted = file.delete();
    System.out.print(file);
    System.out.println( " deleted " + isdeleted);*/
         System.out.println(list[i]);
         if(list[i].contains("_F5029.03_")){
              fileNames.add(list[i]);
              //System.out.println(list[i]);
    dir = null;
    for(int i=0;i<fileNames.size();i++){
         dir = new File(d+"\\"+fileNames.get(i));
         newLoc = new File(newFileLoc+"\\"+fileNames.get(i));
         if(dir.renameTo(newLoc)){
              System.out.println(dir + " is moved to "+ newLoc);
         }else {
              System.out.println("***** " dir " is not moved to "+ newLoc);
         dir = null; newLoc = null;
    for(int i=0;i<list.length;i++){
         dir = new File(d+"\\"+list[i]);
         dir.delete();
    class ExtensionFilter implements FilenameFilter {
    private String extension;
    public ExtensionFilter( String extension ) {
    this.extension = extension;
    public boolean accept(File dir, String name) {
    return (name.endsWith(extension));
    Thanks for replying .......

  • How to read a part of a TDMS file?

    Hi,
    I'm having problems loading back a part of a TDMS file.
    Im currently trying to use the offset and count input on TDMS read.
    But the offset value doesn't seem to make any difference: If I set offset to 5 and count to 10 it still puts out 10 data points.
    By the way:
    Im using labview 8.5, and I multiply the offset and count with the sample rate (100000samples/s) so that offset and count settings input will correspond to seconds of measurement to load.
    I would be very grateful for any help
    Regards
    Carl Zandén 
    Attachments:
    Load part of TDMS file.jpg ‏165 KB

    I am new to TDMS as well so take what I say with a grain (block) of salt.  But as no one else has answered, I'll give it a shot.  First of all, at 100000 S/s and an input for COUNT of 10 X 100000, you will always get 10 seconds worth of data.  Your graph is not showing you 10 data points, it is showing you 10 seconds OF data.  This is expected behavior.  By varying the OFFSET input as you have it you will step through your data 5 seconds (5 X 100000 points) at a time.  So, for IN offset =0 you will see data from 0 to 10 seconds, for IN offset =1 you will see data from 5 to 15 seconds, for IN offset =2 you will see data from 10 to 20 seconds, etc.  You also will probably NOT see the X scale change accordingly as it has no way to know what the initial time of your data set is, unless you tell it.  All it knows is that it has a set of 1M data points with a 1e-6 second delta t.
    Hope this helps.
    Roy

  • How to read,dispaly and open pdf files

    Hi, I am very new to Java butI have VB6.0 background. My current requirement is to read pdf file names from a directory, then
    show them on a form in a list (with their path in background pointing to the actual pdf files) and then once a user clicks any
    file name, open that file on the form.
    For example:
    My pdf files are in a directory as following:
    C:\myreports\user1\
    report1.pdf
    report2.pdf
    report3.pdf
    C:\myreports\user2\
    report1.pdf
    report5.pdf
    The output on the form should look like this if user1 has logged in the system. Side note: I am able to get userid of the logged in person in a variable.
    My Reports:
    . Report 1
    . Report 2
    . Report 3
    When a user clicks Report 1, it opens on the same form in pdf format.
    Thanks
    S.yhong

    For the first part (Listing thepdf files in the directory) you can use the java.lang.File class.
    File f = new File("path to your directory");
    File files[] = f.listFiles();
    then process the files array to find the files with extenction pdf
    You can also use a file filter object and make the listFiles method return only the pdf files.
    Please read the documentation about the File class for more info about it.
    */ For the displaying the pdf part is it good enough if you load the accrobat reader and with it. In that case you can do that using the Runtime.exec
    Also you can search for free java based pdf viewers I am sure there must be meny.
    And also the JTextPane might support pdf but I am not sure about it.
    EDIT:
    Just to say that this is my 1000th post :)
    Message was edited by:
    LRMK

  • How to read the contents of XML file from my java code

    All,
    I created an rtf report for one of my EBS reports. Now I want to email this report to several people. Using Tim's blog I implemented the email part. I am sending emails to myself based on the USERID logic.
    However I want to email to different people other then me. My email addresses are in the XML file.
    From the java program which sends the email, how can I read the fields from XML file. If any one has done this, Please point me to the right examples.
    Please let me know if there are any exmaples/BLOG's which explain how to do this(basically read the contents of XML file in the Java program).
    Thank You,
    Padma

    Ike,
    Do you have a sample. I am searched so much in this forum for samples. I looked on SAX Parser. I did not find any samples.
    Please help me.
    Thank you for your posting.
    Padma.

  • LR 4.2RC and ACR 7.2 RC won't read SONY RX 100 ARW files

    I was at a wedding yesterday and had two cameras with me - a Nikon D800 and my little SONY RX 100.  I was using an Eye-Fi Pro card for the Sony.  I'm uninterested in the Wi-Fi capabilities when I'm away from home, but like the camera to upload pictures when I'm close to my big processing machine.  Long story short.  This was the first time I've used the LR 4.2RC and ACR 7.2RC with the Sony RX 100.  I plugged the card into both the regular Eye-Fi USB reader, and into my Hoodman USB 3.0 reader.  Of course, LR doesn't like the Eye-Fi reader, but it loves the Hoodman.  Finally, it recognized the Hoodman and the Eye-Fi card.  I have previews set to minimal and I was attempting to import all the raw (ARW) files into Lightroom.  When the initial previews come up as I start the import process, it shows about 1/3 of the previews and then tells me it can't read the rest, including MP4 files.  When I actually begin the import, it simply times out and reports that it was unable to import ANY of the ARW files, nor the MP4 files.  I have no trouble reading 63 files into Raw Photo Processor so I know there is nothing wrong with any of the files.  I can only conclude that there is something wrong with LR 4.2 and/or ACR 7.2.
    Anyone else reporting this problem?  I'm puzzled because this is the ONLY time I have ever had trouble importing files from supported cameras.
    Thanks for feedback.

    Well.  After some experimentation, I discovered what the problem seems to be.  For reasons completely opaque to me, Lightroom expects not only that the Eye-Fi card will be read from its own reader, but it also expects that the Eye-Fi helper application be installed and running.  Of course, this means that I end up with duplicate copies of every file - once to the Eye Fi directory, and again to the appropriate Lightroom Folder on a completely different set of drives.   I guess the conclusion I can draw from this is that without the helper application, the Eye Fi card is dumb and the images only partly visibible.  The Eye-Fi helper can import the .ARW files, but it doesn't display them because Apple hasn't updated its camera list to include the RX100.  Until they do, I think I'll just use regular cards and consign the Eye-Fi card to the hall of unhelpful cards.  Yikes, the darned thing is as expensive as the Lightroom upgrade.
    Sigh.

  • How can I input read a line from a file and output it into the screen?

    How can I input read a line from a file and output it into the screen?
    If I have a file contains html code and I only want the URL, for example, www24.brinkster.com how can I read that into the buffer and write the output into the screen that using Java?
    Any help will be appreciate!
    ======START FILE default.html ========
    <html>
    <body>
    <br><br>
    <center>
    <font size=4 face=arial color=#336699>
    <b>Welcome to a DerekTran's Website!</b><br>
    Underconstructions.... <br>
    </font> </center>
    <font size=3 face=arial color=black> <br>
    Hello,<br>
    <br>
    I've been using the PWS to run the website on NT workstation 4.0. It was working
    fine. <br>
    The URL should be as below: <br>
    http://127.0.0.1/index.htm or http://localhost/index.htm
    <p>And suddently, it stops working, it can't find the connection. I tried to figure
    out what's going on, but still <font color="#FF0000">NO CLUES</font>. Does anyone
    know what's going on? Please see the link for more.... I believe that I setup
    everything correctly and the bugs still flying in the server.... <br>
    Thank you for your help.</P>
    </font>
    <p><font size=3 face=arial color=black>PeerWebServer.doc
    <br>
    <p><font size=3 face=arial color=black>CannotFindServer.doc
    <br>
    <p><font size=3 face=arial color=black>HOSTS file is not found
    <br>
    <p><font size=3 face=arial color=black>LMHOSTS file
    <br>
    <p><font size=3 face=arial color=black>How to Setup PWS on NT
    <BR>
    <p><font size=3 face=arial color=black>Issdmin doc</BR>
    Please be patient while the document is download....</font>
    <font size=3 face=arial color=black><br>If you have any ideas please drop me a
    few words at [email protected] </font><br>
    <br>
    <br>
    </p>
    <p><!--#include file="Hits.asp"--> </p>
    </body>
    </html>
    ========= END OF FILE ===============

    Hi!
    This is a possible solution to your problem.
    import java.io.*;
    class AddressExtractor {
         public static void main(String args[]) throws IOException{
              //retrieve the commandline parameters
              String fileName = "default.html";
              if (args.length != 0)      fileName =args[0];
               else {
                   System.out.println("Usage : java AddressExtractor <htmlfile>");
                   System.exit(0);
              BufferedReader in = new BufferedReader(new FileReader(new File(fileName)));
              StreamTokenizer st = new StreamTokenizer(in);
              st.lowerCaseMode(true);
              st.wordChars('/','/'); //include '/' chars as part of token
              st.wordChars(':',':'); //include ':' chars as part of token
              st.quoteChar('\"'); //set the " quote char
              int i;
              while (st.ttype != StreamTokenizer.TT_EOF) {
                   i = st.nextToken();
                   if (st.ttype == StreamTokenizer.TT_WORD) {          
                        if (st.sval.equals("href")) {               
                             i = st.nextToken(); //the next token (assumed) is the  '=' sign
                             i = st.nextToken(); //then after it is the href value.               
                             getURL(st.sval); //retrieve address
              in.close();
         static void getURL(String s) {     
              //Check string if it has http:// and truncate if it does
              if (s.indexOf("http://") >  -1) {
                   s = s.substring(s.indexOf("http://") + 7, s.length());
              //check if not mailto: do not print otherwise
              if (s.indexOf("mailto:") != -1) return;
              //printout anything after http:// and the next '/'
              //if no '/' then print all
                   if (s.indexOf('/') > -1) {
                        System.out.println(s.substring(0, s.indexOf('/')));
                   } else System.out.println(s);
    }Hope this helps. I used static methods instead of encapsulating everyting into a class.

  • How to read a very BIG XML-File

    Hello together,
    how can I read a XML file of e.g. 2 GByte in ABAP ( Release 4.6C ). The file should be read from the Application-Server ( not from the Front-End ).
    Problem: Too much MEMORY is needed by the upload of the complete file into an internal table. In order to produce a stream, the complete file must be uploaded. The parser works with parse_event ( Event-triggered ) and is not creating a DOM. The parsing itself is no problem.
    Possible solution: Feed the stream with parts of the file. But how !?
    Here is some coding of the program:
      data: l_xml_filename    type localfile,
            l_event_sub       type i,
            l_boolean         type c,
            l_subrc           type i.
    Datei mit Größe in XML-Tabelle einlesen:
    l_xml_filename = 'I:TEMPGeboIsp-PSGK37.xml'.
      perform read_file_in_xml_table using    p_xml_filename
                                     changing g_xml_table
                                              g_xml_size.
    XML-Dokument aus Tabelle bilden:     =========================
    iXML factory erzeugen:
      go_ixml = cl_ixml=>create( ).
    stream factory erzeugen:
      p_streamfactory = go_ixml->create_stream_factory( ).
    XML-Dokument erzeugen:
      p_xml_document = go_ixml->create_document( ).
    Input-Stream erzeugen:
      p_istream = p_streamfactory->create_istream_itable(
                          table = g_xml_table
                          size  = g_xml_size ).
      p_parser = go_ixml->create_parser( stream_factory = p_streamfactory
                                         istream        = p_istream
                                         document       = p_xml_document ).
      l_event_sub = if_ixml_event=>co_event_element_pre +
                    if_ixml_event=>co_event_element_post.
      call method p_parser->set_event_subscription( l_event_sub ).
      l_boolean = p_parser->set_dom_generating( ' ' ).
    The program works fine but needs too much memory because of the big internal table.
    I would be very happy if somebody could help me!
    Thanks in advance!
    Thomas
    P.s.: German answers are welcome!  
    Message was edited by:
            Thomas13 Scheuermann
    Message was edited by:
            Thomas13 Scheuermann

    Hello myself,
    nobody has answered my question, so now I answer myself!!  
    The wrong part is to read the file with "open dataset" and to create the inputstream with
    p_istream = p_streamfactory->create_istream_itable(
    table = g_xml_table
    size = g_xml_size ).
    Better ist to create the inputstream with
    p_istream = p_streamfactory->create_istream_uri(
    .......................PUBLIC_ID = ''
    .......................SYSTEM_ID = '
    applserver\I$\TEMP\Datei.XML' ).
    In this way no space is needed for the file.
    Best regards,
    Thomas
    Message was edited by:
            Thomas13 Scheuermann

  • Programming help - how to get the read-only state of PDF file is windows explorer preview is ON?

    Programming help - how to get the read-only state of PDF file is windows explorer preview is ON?
    I'm developing an application where a file is need to be saved as pdf. But, if there is already a pdf file with same name in the specified directory, I wish to overwrite it. And in the overwrite case, read-only files should not be overwritten. If the duplicate(old) file is opened in windows (Win7) explorer preview, it is write protected. So, it should not be overwritten. I tried to get the '
    FILE_ATTRIBUTE_READONLY' using MS API 'GetFileAttributes', but it didn't succeed. How Adobe marks the file as read-only for preview? Do I need to check some other attribute of the file?
    Thanks!

    Divya - I have done it in the past following these documents. Please read it and try it it will work.
    Please read it in the following order since both are a continuation documents for the same purpose (it also contains how to change colors of row dynamically but I didnt do that part I just did the read_only part as your requirement) 
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/f0625002-596c-2b10-46af-91cb31b71393
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/d0155eb5-b6ce-2b10-3195-d9704982d69b?quicklink=index&overridelayout=true
    thanks!
    Jason PV

  • When I download files, firefox is adding " .part " to the file name and the file won't open, but if i back the .part out, it opens fine.

    Firefox seems to be adding " .part " to the file names of files I downoad. Here's an example:
    YuT9iNv8.pdf.part
    I cannot open this file because it can't find an application.
    If I back out the .part, I get a box asking if I want to change the extension to .pdf I check yes, and everything works fine. It doesn't happen with other browsers (Safai).

    I get the error message saying the file could not be downloaded due because there is no enough disk space.
    How large is your HD and how much space do you have left?

  • Using thread to read a big number of files

    Hi all,
    I got a question with THREAD. Can you help me, please?
    I have a class, PragFileLoader, to read many files in a folder. First readDir() reads whole directory and gets a list of file name. Then readFile() reads each file. And finally readLine() reads each line in a file. The problem here is a big number of files. So I have to construct many instances of PragFileLoader. However I should use some kind of lock in a file, which is read by certain PragFileLoader, to let other instances of PragFileLoader know that it's locked therefore these instances won't read the locked file, they gonna to read other files.
    import java.io.*;
    import java.util.Vector;
    public class PragFileLoader extends Thread{
        private Vector v;
         * Constructor
        public PragFileLoader() {
            v = new Vector();
         * Read a line
         * @param str a line to read
        public TrafficDataObject readLine(String fN, String str) {
            // Do something
        public synchronized void readFile(String fileName, File in, File err, File done) {
            try {
                Thread.sleep((int) (Math.random() * 100));
                  // Do something           
            } catch (IOException e) {
                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
            } catch (InterruptedException e) {
                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
            notifyAll();
        public void readDir() {
            //   Vector v = new Vector();
            File in = new File(Preferences.PRAGINBOX);
            File err = new File(Preferences.PRAGERROR);
            err.mkdirs();
            File done = new File(Preferences.PRAGDONE);
            done.mkdirs();
            String[] fileName = in.list();
            for (int i = 0; i < fileName.length; i++) {
                //readFile(fileName, v, in, err, done);
    readFile(fileName[i], in, err, done);
    public Vector getV(){
    return v;
    public void run() {
    for (int i = 0; i < 10; i++) {
    readDir();
    try {
    Thread.sleep((int) (Math.random() * 100));
    } catch (InterruptedException e) {
    And in main() I construct 10 instances of PragFileLoader and I got nothing

    Do you have to make readDir() part of PragFileLoader?
    Why don't you first read the directory once, and then assign the files to a thread each. I don't think it's efficient to have too many file reading threads running at the same time.

Maybe you are looking for