How to read input from a file that is constantly being appended to?

Hi -
My problem is simple, yet very difficult to solve. There is a log file I want to read through, that is actively being written to by another program. I want to be able to block at the eof for more input, much like a network stream can block for more input. However, nothing works.
Here is my snippet so far:
            int ch = '0';
            while( !terminate ) {
                while( (char)ch != ']' ) {
                    ch = isr.read();
                    System.out.print((char)ch);
                System.out.print("\n");
            }Terminate is just a control variable. isr is an InputStreamReader.
The way the log file works is, the end of each line is denoted by a closing box-bracket. So I figured checking for that would be easy enough. The problem with that loop is, it keeps causing my IDE to hang when it runs... It will output the log file contents, but repeatedly, infinite times. I thought the read() method blocks when there is no more input?
Is there anything else I can do to capture new appended text to this file?
I've tried InputStreamReaders and FileInputStreams as well, and they all do the same thing.
Thanks!
-Josh

Yes, I more or less do this. Now I simply open the BufferedReader a few bytes short of the file size (to save on memory usage) and then keep the buffer open. Then I just have the thread sleep for 500ms to not throttle the CPU through the roof. Then I merely check if the buffer does not equal null, if it doesn't, that means there is more stuff to process.
I figure half a second delay maximum is practically realtime, and it is improv enough to do what I need to do.
Thanks for the help.
-Josh

Similar Messages

  • How to read data from a file that was formatted by excel?

    Hi everyone, I'm familiar with java.io and the ability to read from files, can anyone tell me how to read data from a file that was formatted by excel? Or at least give me some web references so that I can learn about it?

    http://jakarta.apache.org/poi/hssf/index.html
    HSSF stands for Horrible Spreadsheet Format, but it still works!

  • How to read data from a file that is already open by another program

    Hey..
    I have made IV, where I'm trying to read data from a log file, that is being updated by another program while my IV runs.
    To be clear, this program writes data continuously to this file and I want to read from the file in LV at the same time.
    The problem is that LV reports an error when I'm trying to read the log file, even if I use to "read only" mode.
    I believe that the program that is producing the file, have some kind of lock on the file. I have tryed to copy the file and then reading from the copied file, but LV throws already an error when I try to copy the file.
    Has anyone tryed this, and found a solution.?
    Additional info: The program that produces the file is STM Studio 
    Best Regards
    Allan

    Hi Alha,
    when that file is locked by the other program you can't do anything about that - apart from quitting that other program. Probably this isn't an option to you…
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • How to read HyperLinks from pdf file??

    hi developer's,
    I am in PDF processing... I am having doubt in that Processing.
    How to read Hyperlinks from PDF file?
    I can able to set the hyperlink.. But i cant able to get the hyperlinks..
    The following example program will set the hyperlink to the PDF file using lowagie API..
    import com.lowagie.text.Anchor;
    import com.lowagie.text.Chunk;
    import com.lowagie.text.Document;
    import com.lowagie.text.DocumentException;
    import com.lowagie.text.Paragraph;
    import com.lowagie.text.html.HtmlWriter;
    import com.lowagie.text.pdf.PdfReader;
    import com.lowagie.text.pdf.PdfWriter;
    public class Argu1 {
         public static void main(String[] args) {
              Document document = new Document();
              try {
                   PdfWriter pdf = PdfWriter.getInstance(document,
                             new FileOutputStream("PageLink.pdf"));
    PdfReader pdf_read=new                
                   document.open();
                   document.add(new Paragraph("Hi Everbody....!"));
                   Anchor pdfRef = new Anchor("Click Me");
                   pdfRef.setReference("www.java2s.com");
                   Anchor rtfRef = new Anchor("Touch Me");
                   rtfRef.setReference("www.sun.com");
                   System.out.println(rtfRef.reference());
                   document.add(pdfRef);
                   document.add(Chunk.NEWLINE);
                   document.add(rtfRef);
              } catch (DocumentException de) {
                   System.err.println(de.getMessage());
              } catch (IOException ioe) {
                   System.err.println(ioe.getMessage());
              document.close();
    Help me how to read the Hyperlinks from the PDF file using java ...
    Thanks in advance,
    With Regards,
    J.Imran

    Instead of cross-posting unformatted code you could have taken a look at the API, because there you might have come across a method named getLinks...Even though it's not documented, I really suspect that it will return the Hyperlinks on a given page.

  • How to read data from a file in OSB

    hi guys,
    Recently, I've got a problem with reading file from specific location. I've actually followed this post OSB 11g - Read or Poll File in OSB - Oracle Fusion Middleware Blog, and then
    I know how to read a file. However, it does not as expected. Because, I've found no way to read data from the file. Therefore, no chance to manipulate the data like assigning to a variable, or extracting ....
    Hence, is there any way to read data from file by using proxy service in OSB ??? No Java code ???
    by the way, supposed that there is no way to read data from a file in OSB. So, What purposes will the way in the post above be used for?
    Many thanks in advance

    http://jakarta.apache.org/poi/hssf/index.html
    HSSF stands for Horrible Spreadsheet Format, but it still works!

  • How to Read data From Excel File in Labview 8.5?

    We can read it from xls file, but it is encrypted..... we need exact data...

    i have attached that excel file...i want to extract the full data from that file..how i can read it...when i read by using "Read from spreadsheet file" function, data was in encrypted form....so please send me the correct way...
    Attachments:
    stn_auto.xls ‏40 KB

  • How to read input from handheld scanner on a keyboard port

    Hi everybody,
    i have an application that should read input from a scanner.
    If i use a jTextField to input scanned data it works fine.
    the problem is that i don't want to use any text component to input data into it.
    And if i set the jtextField not visible then the focus sustem doesnt work.
    I tried to read a buffered input stream from System.in but it doesnt work.
    If the scanner was installed on a serial port i could use javax.comm to monitor it.
    But unfortunately i must use the keyboard wedge thing...
    Do you have any ideas?
    Thank you in advance

    BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()))
    null

  • How to read data from a file

    I have a file that looks like this with out the *'s
    lastName firstName number
    lastName firstName number2
    lastName firstName number3
    lastname = (string) an actual last name like smith same for first name
    number = an actual number (int) like 90 or 120
    I need to read the number from this file and store it in an array. I have some code that I started, but im not sure what to do next. Please help!
    //int searchId;
         int fileData;
         vector <int> employeeIds;
         //cout<<"Enter Employee ID: ";
         //cin>>searchId;
         ifstream dataFile("Small-Database.txt");
         dataFile >> fileData;
         while(!dataFile.eof())
               //this is where i need help, how can i read in a number. i tried using the getLine() function but it did not help
              //employeeIds.push_back(fileData);
              //dataFile >> fileData;
         dataFile.close();Thank you for any help in advance

    The >> operator reads a value corresponding to the target type. For example, to read an integer value, read it into an int variable (or long or long long, depending on the integer range).
    The >> operator skips white space (blanks, tabs, newlines) and then reads characters corresponding to the target type: digits for an integer value, for example. It stops at the first character that cannot be in the representation of the type. If no characters are read, the stream goes into an error state, and further I/O requests are ignored until you clear the stream state.
    You can read each group of data like this:
    std::string first, last;
    int number;
    dataFile >> first >> last >> number;If the data doesn't have the right characteristics, the stream will go into an error state, which you can detect by testing the stream directly:
    if( dataFile ) ...Using EOF as the loop control is not a good idea, since if there is an error, the loop will never terminate. You can do something like this:
    while( dataFile ) {
        std::string first, last;
        int number;
        dataFile >> first >> last >> number;
        if( dataFile ) {
            // ... add first, last, number to the data structure
    } Reading past EOF puts the stream in an error state, so checking the stream state before saving the data and in the loop control will do the trick.
    You can use a char array instead of a string for the names, but then you have to add extra testing to be sure you don't overflow the array, and deal with the extra characters you don't read. Strings will expand as needed. The string is declared as a local variable in the loop, so it gets re-initialized each time through; you don't need to write code to reset it.
    My example loop is not robust in the face of errors. Stream I/O works fine when you know the input data is well-formed. It is not suited to input that can be wrong, such as data typed from the terminal, because it is not easy to validate the input and recover from errors.

  • HELP!!!!   How to read data from a file at time to time?

    i store temporary string data in a file(the data changes always), and i need to read the data in the file from time to time, so how can i read from the file like every 5 seconds?

    Please i need your help mr. noahw. i have a timer called timer1 inside that timer i am starting a thread to read the data in a file to me, then i have another timer timer 2 in which it takes the data already read from timer 1 and draws them on a GUI. the problem with me is that, i am unable to set a correct time for each of the two timers such that, every time timer one executes that is a new data is generated i need to draw only one figure coreesponding to those data, then when a new set of data is read i need to draw another figure based on the new data read, please help me with this becasue i need it urgently, this is my email, [email protected], and i can offer this reply as many points as you want if this helps you to help me, i am counting on you.

  • How to read data from txt file respectively

    Hi,
    I am triying to form an equation between two known points. I want to do this with the attached VI, the most critical point is that I will read the x1, y1, x2 and y2 coordinates from the same .txt file. They will be written in a .txt file and I will send them to the appropriate channel (x1, y1, x2 and y2) respectively. How can I get data in a rule from a .txt file?
    Could anyone please help me with this issue,
    Best regards. 
    Attachments:
    read from txt file.vi ‏8 KB

    Dear RavensFan,
    Thank you very much for your helps, I am bit new to labview so I usually can not find the appropriate functions easily. And a new problem has rised in my application. I should write the A, B and C numbers in the respective series to the file 2.txt. I am able to write them in a straight forward case but I want to write the next triples (A B C) in the next row. Like this;
    A1 B1 C1
    A2 B2 C2
    A3 B3 C3
    So how can I put new line constant and space constant to my VI? 
    Waiting for your valuable helps,
    Best regards,
    Attachments:
    read_from_txt_fileMOD.vi ‏18 KB

  • How to read bits from the file?

    Hello everybody,
    I'm beginner in LabVIEW. I need to get bits from the file, but I don't know how I can do it. I use the example "Read Binary File VI" from LabVIEW Help, but it returns DBL array. And for a long time I can't find a solution to convert this array to array of bits.   Can somebody help me? Thanks in advance. 
    Solved!
    Go to Solution.

    tranonim wrote:
    Hello everybody,
    I'm beginner in LabVIEW. I need to get bits from the file, but I don't know how I can do it. I use the example "Read Binary File VI" from LabVIEW Help, but it returns DBL array. And for a long time I can't find a solution to convert this array to array of bits.   Can somebody help me? Thanks in advance. 
    You can pass in the type into the Read Binary File VI to get the data in whatever form you want.  Just remember that a boolean is really 8 bits.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • How to Read data from excel file without converting a excel file into .csv or any other format

    Hello,
    Can somebody suggest me how to read from an excel file (consisting of 10 work sheets) to an array?
    Thanks,
    She

    You have to be careful when using the spreadsheet-files vi's.  They are located in the Functions Palette under File IO, you will find "Write To / Read From Spreadsheet File.vi"s. 
    Here is what the Context Help says about the vi function:
    "Reads a specified number of lines or rows from a numeric text file beginning at a specified character offset and converts the data to a 2D, single-precision array of numbers. You optionally can transpose the array. The VI opens the file before reading from it and closes it afterwards. You can use this VI to read a spreadsheet file saved in text format. This VI calls the Spreadsheet String to Array function to convert the data. "
    This is quick & easy when the spreadsheet is all the same format.  You can set the format to string as well.  HOWEVER...  you do have to convert the Excel spreadsheet to text before using it.
    I haven't experimented with the Active-X, but it may look as the way to go if you have combination text / numeric values in the spreadsheet.
    If you did convert it to text, then you can use array functions as well and treating the file as an array of strings (see very brief example attached).  The example is to illustrate a point only  
    JLV
    Attachments:
    starting point for spreadsheet.vi ‏28 KB

  • How to read data from a file from a remote area

    Hi,
    i have a jsp page, now i need to read & write data from the file, When i run my program then i give the file path is: "c://sample.txt" if user access this page from remote area to read & write data then what will be the file path? Is there anyone who can solve this problem? What will be the solution of this problem? Please help me.
    With regards
    Bina

    FileReader fr = new FileReader("\\\\pcName\\pcName-Share\\web.xml");
    System.out.println(fr.read());
    fr.close();

  • How to read thai from a file

    Hi
    I am reading data from a excel file using JDBC ODBC. I have three column in excel sheet first two column data is in english and third one in thai language. I am able to retrive the data from the first two column but not the third. I am not able to retrieve the thai data in proper format.
    Please help me.
    Regards
    Arghya

    You need to know the character encoding scheme to open the data stream with.
    Eg. "Windows Thai" is MS874
    check out http://java.sun.com/j2se/1.4/docs/guide/intl/encoding.doc.html
    InputStream columnInputStream = myResultSet.getAsciiStream ( columnNumber );
    InputStreamReader inStreamReader = new InputStreamReader ( columnInputStream, encodingScheme );
    BufferedReader bufReader = new BufferedReader ( inStreamReader );
    String thaiString = bufReader.readLine();

  • How to read data from multiple files and append in columns in one file

    Hi Guys,
    I have a problem in appending data from files in different columns. I have attachement has file A and B which I am reading and not able to get data as in file Result.txt. Please comment on how can I do this
    Solved!
    Go to Solution.
    Attachments:
    Write to file.vi ‏13 KB
    A.txt.txt ‏1 KB
    B.txt.txt ‏1 KB

    You cannot append columns to an existing file. Since the data is arrange line-by-line as one long linear string in the file, you can only append rows. A new row needs to be interlaced into the original file, shifting everything else. If you want to append rows, you need to build the entire output structure in memory and then write all at once.
    (I also don't think you need to set the file positions, it will be remembered from the last write operation.)
    Unless the files are gigantic, here's what I would do:
    (Also note that some of your rows have an extra tab at the end. If this is normal, you need a little bit more code to strop out empty columns. I include cleaned up files in the attachment. I also would not call them A.txt.txt etc. A plain A.txt is probably sufficient.)
    EDIT: It seems Dennis's solution is similar )
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    Write to fileMOD.zip ‏6 KB
    MergeColumns.png ‏6 KB

Maybe you are looking for