How to Read specific data from file and do a calculation and display on the output

FYI: Below is the function use for the writing:
-OpenFile(use ASCII)
-sprintf
-WriteFile
Example: Output from the doc file
…EndTime: 09:34:48 program time: 0.567663 sec
…EndTime: 09:36:48 program time: 0.666666 sec
My objective is to read data 0.666666 (FYI: is last sentence of the file) to do some calculation. How can we read specific data(specific location) from file..
Any advice or help?
What is the function needed?

I would consider counting line feeds and checking for end-of file to isolate the last line, which then can be read using fscanf...
Have a look at getc...
character = fgetc ( stream );
if ( character == '\n' ) // new line
if ( character == EOF ) // end-of-file

Similar Messages

  • How to read a data from USB port using JAVA

    hi all,
    i need to know how to read a data from USB port using java. any API are available for java ?.........please give your valuable ideas !!!!!!!!!
    Advance Thanks!!

    You can do this. Please use this link
    [http://www.google.co.in/search?hl=en&client=firefox-a&rls=org.mozilla%3Aen-US%3Aofficial&hs=uHu&q=java+read+data+from+usb+port&btnG=Search&meta=&aq=f&oq=]
    What research did you do of your own? Have you done some testing application and tried yourself??

  • How to read appended objects from file with ObjectInputStream?

    Hi to everyone. I'm new to Java so my question may look really stupid to most of you but I couldn't fined a solution by myself... I wanted to make an application, something like address book that is storing information about different people. So I decided to make a class that will hold the information for each person (for example: nickname, name, e-mail, web address and so on), then using the ObjectOutputStream the information will be save to a file. If I want to add a new record for a new person I'll simply append it to the already existing file. So far so good but soon I discovered that I can not read the appended objects using ObjectInputStream.
    What I mean is that if I create new file and then in one session save several objects to it using ObjectOutputStream they all will be read with no problem by ObjectInputStream. But after that if in a new session I append new objects they won't be read. The ObjectInputStream will read the objects from the first session after that IOException will be generated and the reading will stop just before the appended objects from the second session.
    The following is just a simple test it's not actual code from the program I was talking about. Instead of objects containing different kind of information I'm using only strings here. To use the program use as arguments in the console "w" to create new file followed by the file name and the strings you want save to the file (as objects). Example: "+w TestFile.obj Thats Just A Test+". Then to read it use "r" (for reading), followed by the file name. Example "+r TestFile.obj+". As a result you'll see that all the strings that are saved in the file can be successfully read back. Then do the same: "+w TestFile.obj Thats Second Test+" and then read again "+r TestFile.obj+". What will happen is that the strings only from the first sessions will be read and the ones from the second session will not.
    I am sorry for making this that long but I couldn't explain it more simple. If someone can give me a solution I'll be happy to hear it! ^.^ I'll also be glad if someone propose different approach of the problem! Here is the code:
    import java.io.*;
    class Fio
         public static void main(String[] args)
              try
                   if (args[0].equals("w"))
                        FileOutputStream fos = new FileOutputStream(args[1], true);
                        ObjectOutputStream oos = new ObjectOutputStream(fos);
                        for (int i = 2; i < args.length ; i++)
                             oos.writeObject(args);
                        fos.close();
                   else if (args[0].equals("r"))
                        FileInputStream fis = new FileInputStream(args[1]);
                        ObjectInputStream ois = new ObjectInputStream(fis);
                        for (int i = 0; i < fis.available(); i++)
                             System.out.println((String)ois.readObject());
                        fis.close();
                   else
                        System.out.println("Wrong args!");
              catch (IndexOutOfBoundsException exc)
                   System.out.println("You must use \"w\" or \"r\" followed by the file name as args!");
              catch (IOException exc)
                   System.out.println("I/O exception appeard!");
              catch (ClassNotFoundException exc)
                   System.out.println("Can not find the needed class");

    How to read appended objects from file with ObjectInputStream? The short answer is you can't.
    The long answer is you can if you put some work into it. The general outline would be to create a file with a format that will allow the storage of multiple streams within it. If you use a RandomAccessFile, you can create a header containing the length. If you use streams, you'll have to use a block protocol. The reason for this is that I don't think ObjectInputStream is guaranteed to read the same number of bytes ObjectOutputStream writes to it (e.g., it could skip ending padding or such).
    Next, you'll need to create an object that can return more InputStream objects, one per stream written to the file.
    Not trivial, but that's how you'd do it.

  • How to read some images from file system with webdynpro for abap?

    Hi,experts,
    I want to finish webdynpro for abap program to read some photos from file system. I may make MIMES in the webdynpro component and create photos in the MIMES, but my boss doesn't agree with me using this way. He wish me read these photos from file system.
    How to read some images from file system with webdynpro for abap?
    Thanks a lot!

    Hello Tao,
    The parameter
       icm/HTTP/file_access_<xx>
    may help you to access the pictures without any db-access.
    The following two links may help you to understand the other possibilities as well.
    The threads are covering BSP, but it should be useful for WebDynpro as well.
    /people/mark.finnern/blog/2003/09/23/bsp-programming-handling-of-non-html-documents
    http://help.sap.com/saphelp_sm40/helpdata/de/c4/87153a1a5b4c2de10000000a114084/content.htm
    Best regards
    Christian

  • Get data from file in server to client and vice versa

    after greeting
    i really didn't know how to use socket and serversocket to get data from file in the server and display it to client.
    also read file from client and save it to server.
    really i didn't know how to do it.
    really i want the reply as soon as possible

    You REALLY need to work through the Java networking tutorials:
    http://java.sun.com/docs/books/tutorial/networking/index.html

  • How to read a string from file & assign the val to a variable in batch file

    Hi,
    How to read a string from a file and assign the value to a variable then return the value to the screen in windows batch file?
    Any suggestions?
    thanks.

    Unless this is a homework question then I don't see the purpose of doing this, but....
    You should be looking a the supplied package utl_file to get the string out of the file, dbms_output to display the string and then google windows batch/command files calling sqlplus to execute your program.
    Andre

  • How to read specific fields from BW table  into ABAP?

    Hi Experts,
    Can someone help me how to use to FM: RFC_READ_TABLE to read specific fields from a BW  table '/bic/zcust_chO01' which DOESN't EXIST IN ABAP.
    I am getting an error in OPTIONS & DATA parameters.
    Any help would be higly appreciated with points.
    Thanks
    Dan

    Dan,
    FM: RFC_READ_TABLE is a RF FM so by providing BW system's RF destination you can get the values from required table.
    TRY this:
    CALL FUNCTION RFC_READ_TABLE destination <BW_RF_destination>
    Susanth.

  • How to read configuration data from an xml file (not web.xml)?

    Hi,
    I want to separate the application specific configuration parameters in a separate xml file and read them as and when they are needed? I know that I can use the wb.xml but I want to separate them in a different xml file because I don't want the web.xml file to be played around later after deployment. If any change is needed then it should be done in the application-config.xml.
    How can I read the parameters from this xml file in my jsp code and also what should be the location of this file if I have
    ../webapps/Root/application
    directoty structure ?
    Any help is greatly appreciated.

    can you give an example of a property file and also
    it is loaded in the jsp ?Hmm... loading properties in a JSP is not a very good idea. You should do it in a separate class, rather than mixing the logic with the display logic.
    Properties properties = new Properties();
    properties.load(UtilClass.class.getResourceAsStream("config.properties"));
    // Add a try - catch block around the load
    // for IOException...

  • How to read updated data from a real-time generated file?

    I have a question:
    I want to read the 10 mostly updated data from a real time generated data file. The data in this file is accumulated. how can i read mostly recently data to an applet? and further to using this data to draw a real-time graph? pls help
    kelvin t.l. tse

    Hi,
    I think there is no "typical" way. You will have to define a convention on how the new data are stored into the file, so as to know how to accessthem. If new data are simply put at theend of your file, you may use a RandomAccessFile to read only those lines that interest you (the 1 final lines).Otherwise, you should at least know how the data file is written.
    You can know if thedata file has been modified with the File.lastModified() method. This retrurns a long value corresponding to the date and hour the file was last modified. Store that value ito you appl. and perdiodically (use a Thread), compare that value with the value returned by lastModief(). If both value are NOt equal, then the file has been updated
    it's all a question of knowing how the data are stored into the datafie generated.
    Be also aware that you will probably have problem when your java appl. tries to read the file at the same time it is updated by the other application. I guess when theother application writes data into the file, you will not be able to read it. So, use try{} catch statements and first check to see if you can read the file with File. canRead(). If not, simply delay the reading process by asking a Thread.yield() or Thread.delay (1000)...
    vincent

  • Read XML data from file

    Hello!
    I have data in an xml file which i want to read into my program. The problem is i do not want to parse the whole file at once, but in sequece, maybe in to or three sequences. In other words i want to parse the frist part of the file, and then the next sequence.
    Is this possible and how? I use a SAXParser right now, but it parses the whole file at once. Examles and refrences to java api is appreciated
    Best Regards
    Yoshi

    Ok!
    the problem is not to call the function several times, but that the function parse in SAXParser parses the whole xml file at once, so im not sure how a switch case loop is going to help me, maybe you could clarify a little.
    The data in the xml file contains history im going to read into the program, simulating progress. each root element contains a progress. So i want to read one element at a time everey time i call the parse function or a function containing the SAXParse function
    like this
    <datafile>
    <loggfile>
    <time>10:11</time>
    <data>12323></data>
    </loggfile>
    <loggfile>
    <time>10:12</time>
    <data>12424</data>
    </loggfile>
    </datafile>
    best regards
    Yoshi

  • Urgent!! Help me - Read formatted data from file

    Hi,
    I have a file which contains(line by line) :
    [0.0577, 0.0769, 0.0385, 0.0, 0.0]
    [0.0577, 0.1346, 0.0962, 0.0, 0.0]
    [0.0192, 0.0, 0.0577, 0.1154, 0.0962]
    How can i read the file line by line(exluded "[" and "]" symbols) and assign each line to an array?
    Thanks

    full code regarding readin/writing
    import java.net.*;
    import java.io.*;
    import java.util.*;
         public class FtpWrite {
                   static StringBuffer Data = new StringBuffer(20);
             public static void main(String[] args) throws Exception {
                   int jobNumber = 10006;
                   String dataOut = "Liam Charles Rangers";
                   URL ftpUrl = new URL("ftp://username:[email protected]/dataOutput.txt");
                           URLConnection conn = ftpUrl.openConnection();
                   conn.setDoOutput(true);
                           OutputStream out = conn.getOutputStream();
                   PrintWriter writer = new PrintWriter(out);
                           System.out.println("Writing to ftp");
                   writer.print(jobNumber);
                   writer.print('\t');
                   writer.print(dataOut);
                   writer.print('\n');
                           writer.close();
                   out.close();
                   String dataIn;
                   InputStream inFile = ftpUrl.openStream();
                   BufferedReader in = new BufferedReader(new InputStreamReader(inFile));
                   dataIn = in.readLine();
                   System.out.println("The data is" + dataIn);
                   in.close();
                     StringTokenizer parser = new StringTokenizer(dataIn);
                       while (parser.hasMoreTokens()) {
                             System.out.println(parser.countTokens());
                             processWord(parser.nextToken(),parser.countTokens());}
                   public static void processWord(String token, int position){
                   int jobNumber = 0;
                   System.out.println("in process word token = " + token + " at position" + position );
                   if (position == 3)
                        jobNumber = Integer.parseInt(token);
                   jobNumber = jobNumber * 2;
                   System.out.println(jobNumber);
                   if((position <3) && (position>=0))
                        Data.append(token);
                        Data.append(' ');
                   System.out.println("Data is " + Data);
    }this code has just been completed with a bit of help. I gave it to you warts and all.
    Jim

  • How to read in data from MySQL to Authorware?

    Hi,
    I am trying to read in values from my database (MySQL) to
    authorware, but the best I am able to get is true or false.
    I would like to be able to get some data from the database
    and return it to AW as a string. Does anyone have any experience
    with this? Can anyone lend a helping hand in this endeavor?
    Thanks in advance for your help,
    Brad

    "Paul Swanson" <[email protected]>
    wrote in message
    news:[email protected]...
    > Kevin, you shouldn't need to worry about ODBC or OLEDB.
    Your PHP script
    > needs to handle the database connection, and you can use
    PHP's
    > mysql_connect() function for that. You really don't need
    to do anything
    > different for Authorware than you do for any PHP/MySQL
    application in
    > terms
    > of connecting to the database.
    >
    > My PHP script returns data to AW in the form of
    name=value pairs delimited
    > by the ampersand character. I then use the following
    code in AW to convert
    > them into lists:
    >
    > =========================
    > -- Use this routine to break queryString into name /
    value arrays.
    > -- Assumes a database query returns a string of
    name=value pairs
    > -- delimited by the ampersand (&) character.
    >
    > -- strip leading & from queryString
    > queryString := SubStr(queryString, 1,
    CharCount(queryString))
    >
    > -- break into list of individual lines
    > tempList := Replace("&", Return, queryString)
    >
    > listLength := LineCount(tempList)
    >
    > -- create empty arrays for name and value
    > name := Array("", listLength)
    > value := Array("", listLength)
    >
    > repeat with counter := 1 to listLength
    > singleLine := GetLine(tempList, counter)
    > name[counter] := GetWord(1, Replace("=", " ",
    singleLine))
    > value[counter]:= GetWord(2, Replace("=", " ",
    singleLine))
    > end repeat
    >
    > -- now you will need to add a separate calc icon with a
    routine to
    > -- read the data from the arrays. name[counter] matches
    value[counter]
    > =========================
    >
    > I follow this with another Calc icon (I could have done
    it all in one
    > calc)
    > that parses the names and assigns the values to my
    custom AW variables:
    >
    > =========================
    > -- get just the info we want, and store in variables
    >
    > repeat with counter := 1 to listLength
    > if name[counter] = "Lesson1Complete" then
    > Lesson1Complete := Number(value[counter])
    > else if name[counter] = "Lesson2Complete" then
    > Lesson2Complete := Number(value[counter])
    > else if name[counter] = "Lesson3Complete" then
    > Lesson3Complete := Number(value[counter])
    > else if name[counter] = "Lesson4Complete" then
    > Lesson4Complete := Number(value[counter])
    > else if name[counter] = "Lesson5Complete" then
    > Lesson5Complete := Number(value[counter])
    > else if name[counter] = "Lesson6Complete" then
    > Lesson6Complete := Number(value[counter])
    > else if name[counter] = "Lesson7Complete" then
    > Lesson7Complete := Number(value[counter])
    > else if name[counter] = "Lesson8Complete" then
    > Lesson8Complete := Number(value[counter])
    > else if name[counter] = "OverviewComplete" then
    > OverviewComplete := Number(value[counter])
    > else if name[counter] = "grade" then
    > score := Number(value[counter])
    > else if name[counter] = "passed" then
    > passed := Number(value[counter])
    > end if
    > end repeat
    I'd like to point out here that any time you have a series of
    variables that
    all have identical names except for a number in the variable
    name, you
    should be looking at lists. I'm surprised, Paul, that you
    have lists used
    to the extent that you're able to use Value[counter] on the
    right side of
    the equation, yet you're not using lists on the left side of
    the equation.
    Let's look at how this code could be made super simple by
    having ONE list
    variable, LessonComplete, instead of Lesson1Complete through
    Lesson8Complete.
    -- Assumes a database query returns a string of name=value
    pairs
    -- delimited by the ampersand (&) character.
    -- strip leading & from queryString
    --(note you could also not add this ampersand on the PHP
    side)
    queryString := SubStr(queryString, 1, CharCount(queryString))
    -- break into list of individual lines
    tempList := Replace("&", Return, queryString)
    listLength := LineCount(tempList)
    -- create empty arrays for name and value
    name := Array("", listLength)
    LessonComplete := []
    repeat with counter := 1 to listLength
    singleLine := GetLine(tempList, counter)
    name[counter] := GetWord(1, Replace("=", " ", singleLine))
    LessonComplete[name[counter] * 1] := GetWord(2, Replace("=",
    singleLine))
    end repeat
    -- now you will need to add a separate calc icon with a
    routine to
    -- read the data from the arrays. name[counter] matches
    value[counter]
    --No you don't...You're DONE :-)
    Also note that this is extensible...you can have Lesson 9,
    10, etc. and not
    have to change the code. You can also lower the amount of
    data being
    transmitted, because now instead of Lesson8Complete=1 all you
    need is 8=1.
    This lowers the server load and speeds the response. It has
    advantages on
    the Authorware side as well, because if, for instance, you
    had a series of
    buttons that were checked or not based on the completion, you
    could do the
    same type of loop. Separate variable names do not allow for
    that type of
    loop unless you use Eval (ugh).
    HTH;
    Amy

  • How to read Image data from oracle DB?

    How to read a oracle database object ORDSYS.ORDImage from oracle
    database?
    I can get a oracle.sql.STRUCT object from the database, but i can not
    find the way to convert data to a image object(like oracle.ord.im.OrdImage)
    I had used "OrdImage imgObjj1 =
    (OrdImage)rs.getCustomDatum(1, OrdImage.getFactory());"
    it's a example from oralce.
    But OracleResultSet.getCustomDatum() method is already deprecated,
    i can't find a new method to instead of it.
    Who can help me ? Thank you!
    [email protected]

    More than likely, this is the interface you will use:
    java.sql.Blob
    http://java.sun.com/j2se/1.4/docs/api/java/sql/Blob.html
    Once you get the blob, construct a Raster objects from the Bytes you receive from the blob. Then you can create an Image, ImageIcon, BufferedImage, whatever with the Raster object.
    Good luck!

  • How to read xml data from jsf,

    Hi
    I would like to know how to read data in an xml so as we can display that data onto the jsf page to the user, say as a data table, or in an output txt box etc...

    This is nothing JSF-special. Just convert XML to objects (DTO's) and then use them in JSF.
    There are several ways to crawl the XML tree. JXPath and DOM4J are popular.

  • How to recover lost data from a mac that was erased and locked using findmyiphone app

    Hi,
    My macbook pro was locked and erased using find my iphone app then it was recovered. I entered my pin and unlocked it. I then have the option to reinstall the OS on a new hard drive or my old one (which is blocked).
    What do I do if i want to recover all of my old data?

    Alas the answer is : NO
    If you have an external HD, you may try tun run a recovery tool instlled on this external device searching for keystring "index.xml"
    With a bit of luck, it will retrieve an old copy of your document.
    I hope that this time you will understand that working the way you did is playing with matches.
    Whe you work on a document already saved once, duplicate the document before opening it and check that both copies are OK.
    This way you will have at least a copy containg the datas from the 25 first day.
    During the working session, don't save with the name of the opened doc, save vert ten minutes with different names.
    Doing that you will recover at least the copy which you opened.
    Yvan KOENIG (VALLAURIS, France)  jeudi 10 janvier 2011 21:27:19
    iMac 21”5, i7, 2.8 GHz, 4 Gbytes, 1 Tbytes, mac OS X 10.6.8 and 10.7.2
    My iDisk is : <http://public.me.com/koenigyvan>
    Please : Search for questions similar to your own before submitting them to the community

Maybe you are looking for