BufferedReader/FileWriter - read in a line and store it in a file

hi, I'm new in programming java, so I hope somebody can help me with the following question:
I've got a file that contains parameters, which change every second (the file updates itself every second)
Now I have to write a java Programm, that reads in a certain parameter of that file, and store it in another file, so that the file lists every read-in parameter (to show the changes of the parameter).
the following source shows a programm, that reads in the content of a text file and stores it in another file - every second. Please, could anyone be so kind, and help me to change the programm?
import java.io.*;
import java.util.Date;
public class readIn {
public static void main(String[] args) throws IOException {
for (int i = 1; i <= 5; ++i) {
System.out.println("Sleep at: " + new Date());
try
// ask currently executing Thread to sleep for 1000ms
Thread.sleep(1000);
catch(InterruptedException e)
System.out.println("Sleep interrupted:"+e);
if (args.length != 2)
System.err.println ("usage: pattern file");
System.exit (1);
String patt = args [0];
String fileIn = args [1];
try
LineNumberReader reader = new LineNumberReader
(new FileReader (fileIn));
String str;
while ((str = reader.readLine()) != null)
if (str.indexOf (patt) != -1)
int ln = reader.getLineNumber();
File inputFile = new File("logfile.txt");
File outputFile = new File("history.txt");
FileReader in = new FileReader(inputFile);
FileWriter out = new FileWriter(outputFile);
int c;
while ((c = in.read()) != -1)
out.write(c);
in.close();
out.close();
reader.close();
catch (IOException e)
System.err.println ("IO-Fehler beim Filtern");
e.printStackTrace();
System.out.println("Awoke at: " + new Date());
the logfile.txt contains words which change every second. I want to permanently read in the third line.
anatomy
animation
applet
application
argument
bolts
class
communicate
component
container
development
environment
exception
graphics
image
input
integrate
interface
Thank you very much for your immediate answer!!

RandomAccessFile ??
aha, I took a look at the API but I have no idea how to work with it. If its quite easy, could you please be so kind and tell me ?? thanks ;)

Similar Messages

  • I have a family video DVD that was originally on tape, but is now on disc. I want to import it onto my MacBook to edit and store. However the files are IFO, BUP and VOB and the Mac is saying 'unable to import' as it doesn't recognise the file. Help !!

    I have a family video DVD that was originally on tape, but is now on disc. I want to import it onto my MacBook to edit and store. However the files are IFO, BUP and VOB and the Mac is saying 'unable to import' as it doesn't recognise the file. Help please !!!!!

    Those are the constituent parts of a standard mpeg2 DVD. Storing them is easy: just copy the folder to your hard drive and they will play in DVD player or VLC.
    But that format is not intended for editing. To do so:
    You need to convert the VOB files in the TS-Folder of the DVD back to DV which iMovie is designed to handle. For that you need mpegStreamclip:
    http://www.squared5.com/svideo/mpeg-streamclip-mac.html
    which is free, but you must also have the  Apple mpeg2 plugin :
    http://store.apple.com/us/product/D2187Z/A/quicktime-mpeg-2-playback-component-f or-mac-os-x
    (unless you are running Lion in which case see below))
    which is a mere $20.
    Another possibility is to use DVDxDV:
    http://www.dvdxdv.com/NewFolderLookSite/Products/DVDxDV.overview.htm
    which costs $25.
    For the benefit of others who may read this thread:
    Obviously the foregoing only applies to DVDs you have made yourself, or other home-made DVDs that have been given to you. It will NOT work on copy-protected commercial DVDs, which in any case would be illegal.
    And from the TOU of these forums:
    Keep within the Law
    No material may be submitted that is intended to promote or commit an illegal act.
    Do not submit software or descriptions of processes that break or otherwise ‘work around’ digital rights management software or hardware. This includes conversations about ‘ripping’ DVDs or working around FairPlay software used on the iTunes Store.
    If you are running Lion:
    From the MPEG Streamclip homepage
    The installer of the MPEG-2 Playback Component may refuse to install the component in Lion. Apple states the component is unnecessary in Lion onwards, however MPEG Streamclip still needs it. See this:
    http://support.apple.com/kb/HT3381
    To install the component in Lion, please download MPEG Streamclip 1.9.3b7 beta above; inside the disk image you will find the Utility MPEG2 Component Lion: use it to install the MPEG-2 Playback Component in Lion. The original installer's disk image (QuickTimeMPEG2.dmg) is required.
    The current versions of MPEG Streamclip cannot take advantage of the built-in MPEG-2 functionality of Lion. For MPEG-2 files you still need to install the QuickTime MPEG-2 Playback Component, which is not preinstalled in Lion. You don't have to install QuickTime 7.

  • How to send array of bytes to a servlet and store it in a file

    Hi,
    How to send array of bytes to a servlet and store it in a file.
    I am new to Servlets. if possible for any one, please provide the code.
    Thanks,
    cmbl

    Through HTTP this is only possible with a POST request of which the encoding type is set to multipart/form-data. You can use Apache Commons FileUpload to parse such a multipart form data request into useable elements. From the other side (the client) you can use a HTML <input type="file"> element or a Java class with Apache Commons PostMethod API.
    You may find this article useful: http://balusc.blogspot.com/2007/11/multipartfilter.html

  • UDF for reading a particular line and storing the value in a variable

    Hi Experts,
    I am reading entire file content in single feild in source data type.I want to write a UDF to seach for a particular pattern(say :25: and store the value after it i.e  34535764778 detination for further use).
    EX: My  sample file and its  has feilds like
    point assured
    Thanks

    Hi since u are using a single field only then u dont need to use any advanced function
    Wel because if u see the formation of the queue u wil find the the whole data is under one context.. and there are not more context changes
    Convert the string to an array and progressively u can check for the four checks if the a<i>=:
    then a[i+]=2 then a[i]=5 and a[i+] =: and then substring the next 7-8 chrac.. hope u understand
    If this also doesnt work wel then u will have to use the Pattern class in Java
    By the way remember that the substring value cant be retained for the next instance of mapping
    Hope u have that in mind...
    Rgds
    Aditya

  • Read data from .xls and store it in blob

    Hi,
    I am getting the file using CLIENT_GET_FILE_NAME. I need to read the data from the .xsl file and convert it into blob. The file should not be stored in DB.
    Please help me by providing suggestions / solutions.
    Thanks.
    Edited by: tharini on 10-Aug-2010 04:16

    InoL,
    You can use an OLE Container or you can use a database stored procedure to write the file to the BLOB or extract the file from the BLOB. Then, using WebUtil you can serve the file to the the user. Of course, you would use WebUtil to allow the user to upload the document to the server so you can call the stored proc to load the file into the BLOB.
    The file should not be stored in DB.Hence my question:
    Why do you want to store the raw data from the spreadsheet in a BLOB instead of the file in a BLOB?What is the business requirement and how do you plan on using the data once it is stored in the BLOB?
    If it is a hard requirment to not store the file, then tharnini has to figure out how to take the contents read from the .xls file using WebUtil and store this in the BLOB. More importantly, how do you take the contents of the file stored in the BLOB and write it back out to a file in the same format as the original file so the user can view the information.
    I've not done this using the aforementioned method - I've not done using the OLE container either. ;-)
    Craig...
    Edited by: CraigB on Aug 10, 2010 12:49 PM

  • How do I read a text file line by line and store to array

    I have a text file, I want to be able to store each line of the file in an array, how would I go about doing this? code example? tutorial? Thank you

    Well, you got the pseudo code:
    a) read line
    b) add to array
    So whats the problem? What don't you know how to do?
    What does your text book tell you about reading files. I'm sure it has an example, every book I've read does.
    By the way I would use an ArrayList to store each line of text, that way you don't need to know in advance.

  • C# WPF read a .txt file line by line and store it to listview with GridViewColumn

    I have a .txt file with text in the following format:
    Name Pid CPU Thd Hnd Priv CPU Time Elapsed Time
    Idle 0 99 8 0 0 203:18:16.647 26:02:53.315
    I want to store it in a listview with a GridViewColumn. Name is one GridViewColumn and in this I want to store, for example, Idle. How can I do this?

    Unfortunately your post is off topic as it's not specific to Microsoft Training and Certification.  
    This is a standard response I’ve written in advance to help the many people who post their question in this forum in error, but please don’t ignore it.  The links I provide below will help you determine the right forum to ask your question in.
    For technical issues with Microsoft products that you would run into as an end user, please visit the Microsoft Answers forum ( http://answers.microsoft.com ) which has sections for Windows, Hotmail,
    Office, IE, and other products.
    For Technical issues with Microsoft products that you might have as an IT professional (like technical installation issues, or other IT issues), please head to the TechNet Discussion forums at http://social.technet.microsoft.com/forums/en-us, and
    search for your product name.
    For issues with products you might have as a Developer (like how to talk to APIs, what version of software do what, or other developer issues), please head to the MSDN discussion forums at http://social.msdn.microsoft.com/forums/en-us, and
    search for your product or issue.
    If you’re asking a question particularly about one of the Microsoft Dynamics products, a great place to start is here: http://community.dynamics.com/
    If you think your issue is related to Microsoft Training and Certification and I've flagged it as Off-topic, I apologise.  Please repost your question and include as much detail as possible about your problem so that someone can assist you further. 
    If you really have no idea where to post your question please visit the Where is the forum for…? forum http://social.msdn.microsoft.com/forums/en-us/whatforum/
    When you see answers and helpful posts, please click Vote As Helpful,
    Propose As Answer, and/or Mark As Answer
    Jeff Wharton
    MSysDev (C.Sturt), MDbDsgnMgt (C.Sturt), MCT, MCPD, MCSD, MCSA, MCITP, MCDBA
    Blog: Mr. Wharty's Ramblings
    Twitter: @Mr_Wharty
    MC ID:
    Microsoft Transcript

  • Powershell script - how to read a registry hive and store the value in text file and then again read the text file to write the values back in registry

    Hi All,
    powershell script Method required to read a value from registry and then taking the backup of that values in some text file.
    For example the hive is
    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\Path
    and under path i need to take back up  of values in some text file and then put some value in the registry after back is taken in text file.
    Also how to read the text file values so that we can again write to registry hive  back from the back up text file.
    Your help is much appreciated.
    Umeed4u

    I think you need to read this first:
    http://social.technet.microsoft.com/Forums/scriptcenter/en-US/a0def745-4831-4de0-a040-63b63e7be7ae/posting-guidelines?forum=ITCG
    Don't retire TechNet! -
    (Don't give up yet - 12,830+ strong and growing)

  • Preserving Line and Tab Spaces in XML File

    Hi all,
    Question is in detail
    I want to preserve spaces in my XML Document.
    XML File is as follows
    <?xml version="1.0" encoding="UTF-8"?>
    <desc xml:space = "prserved">          AAA&#xD;
    &#xD;
    Customer Id: [ customer_id ]&#xD;
    Customer Id: [ customer_id ]&#xD;
    Customer Id: [ customer_id ]&#xD;
    Customer Id: [ customer_id ]&#xD;
    Customer Id: [ customer_id ]&#xD;
    </desc>
    Output of the XML File Should be like this
    AAA
    Customer Id: [ customer_id ]
    Customer Id: [ customer_id ]
    Customer Id: [ customer_id ]
    Customer Id: [ customer_id ]
    Customer Id: [ customer_id ]
    i want same output that what you see above, when i am converting xml file to pdf file.
    First, i am generating XML File dynamically
    Second, i am writing XSL File(Predefined)
    Third, Using FOP, i am converting XML to PDF(By Using XSL File)
    Here is My XSL File
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
    <xsl:preserve-space elements="desc"/>
    <xsl:template match="/">
    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
         <fo:layout-master-set>
              <fo:simple-page-master master-name="simple">
                   <fo:region-body margin-left = "2cm" margin-right = "2cm" margin-top = "2cm" margin-bottom = "2cm"/>
              </fo:simple-page-master>
         </fo:layout-master-set>
         <fo:page-sequence master-name="simple">
              <fo:flow flow-name="xsl-region-body">
                   <xsl:apply-templates select="desc"/>
              </fo:flow>
         </fo:page-sequence>s
    </fo:root>
    </xsl:template>
    <xsl:template match="desc">
    <fo:block font-weight="bold" color = "brown"><xsl:value-of select="."/></fo:block>
    </xsl:template>
    </xsl:stylesheet>
    i used (space preserving) attributes in XML File and XSL File also. But i am getting below output.
    AAACustomer Id: [ customer_id ]Customer Id: [ customer_id ]Customer Id: [ customer_id ] Customer Id: [ customer_id ]Customer Id: [ customer_id ]
    Please help me.

    Thanks for your Response
    I want to preserve space when i convert xml file to pdf. So we need to use FO
    attributes.
    <fo:block wrap-option="no-wrap" white-space-collapse="false"><xsl:value-of
    select="."/>
    </fo:block>

  • Urgently need EwsJavaApi example to read email from exchange, and print text attachment to file.

    Hello,
    I have the below code running using the EwsJavaApi. I need to modify it to read the the first email that matches the search string, and then save it's attachment to a file.... Thank you in advance!!!
    public class EWSDemo {
    * @param args
    public static void main(String[] args)  throws Exception {
    ExchangeService service = new ExchangeService();
     // Provide Crendentials
     ExchangeCredentials credentials = new WebCredentials("[email protected]", "yubbybuddy");
     service.setCredentials(credentials);
     // Set Exchange WebSevice URL
     service.setUrl(new URI("https://outlook.office365.com/EWS/exchange.asmx"));
     // Get five items from mail box
     ItemView view = new ItemView(5);
     // Search Inbox
     FindItemsResults<Item> findResults = service.findItems(WellKnownFolderName.Inbox,"Subject:ROGERDODGER123", view);
     // iterate thru items
     for (Item item : findResults.getItems()) {
      System.out.println(item.getSubject());
      AttachmentCollection myAttachments = item.getAttachments();
      System.out.println(myAttachments.);

    >> I need to modify it to read the the first email that matches the search string
    By first do you mean then newest email to arrive or the oldest email in the Mailbox that matches that string ?
    Exchange returns Items from Newest to oldest by default if you want the older messages then you can use the OrderBy property
    http://msdn.microsoft.com/en-us/library/microsoft.exchange.webservices.data.itemview.orderby(v=exchg.80).aspx which should give you the oldest item
    Cheers
    Glen

  • I am trying to generate a 50kHz sine wave for ten cycles, then aquire this waveform and store it in a file, I am using a PCI-Mio 16E-4 board, has anyone done anything like this?

    I am trying to generate a 50kHz sine wave output on the DAQ card and then simultaneously recieve. I am using a PCI-Mio 16E-4 series board to do this. Has anyone done anything similar. I can generate a 50k wave no problem, and recieve one, but I can not get these vis to run together? Any suggestiosn

    Jrod, yes you should be able to do this, actually there are quite a few example programs come with LabVIEW that handles simultaneous analog input and output, I check the specs of the board you use, the board should be able to handle the sampling/generation rate, but make sure for 50KHz sine wave, you would sample at least twice as fast, preferably ten times the generation rate, then this puts the sampling of the board to thew limit.
    The program you can try is attached here, good luck with the application,
    XD Gao
    Applications Engineering,
    National Instruments
    Attachments:
    Simul_AIAO_Buffer(E-series).vi ‏104 KB

  • Reading in a line of text and breaking it up, complicated

    Hi all,
    At the moment im reading in a few 100 lines of text from a file, each line contains a command and a few variables which need to be set to existing variables I have created shown below;
    Int variableA ;
    Int variable B ;
    Int variable C;
    Int Variable D;
    However I have no way to know which command will go with which variables,
    On every line there will be one command and two variables..
    The possible command are; ADD, SUB, TIMES, Divide, COPY, SET
    And the text coming in look like this;
    SET A10, B15 // set each variable
    SET C33, D50 // as above
    COPY A, B // which means assign copy what ever in variableA to variableB
    ADD C, D // which mean add variableC�s contents to variableD contents
    SUB B, C // which is subtract variableC contents by what ever is in variableB
    Does anybody know of a way where I can test what the next command is, and assign the correspond variables , so far I have come up with;
    But am not sure if this is the best way to go about it, was thinking maybe I should put the text file into an array, which might make it easyer to process.
    public static void main (String [] args)
    int D = 0 ;
    int C = 0 ;
    int B = 0 ;
    int A = 0 ;
    StringTokenizer st ;
    String line ;
    String buffer = "";
    String file ="test2.txt" ;
    String name = "";
    String billy = "";
    try
    FileReader fr = new FileReader(file) ;
    BufferedReader inFile = new BufferedReader (fr) ;
    //read in one line @ a time
    buffer =inFile.readLine() ;
    while (buffer !=null)
    StringTokenizer words = new StringTokenizer (buffer) ;
    //put the buffer "line" into a tokenizer for individual characters out of a line;
    while(words.hasMoreTokens())
    String letter = words.nextToken() ;
    if(letter.charAt (0) == 'S') // if first letter = S would be SET
    System.out.println(letter) ;
    //display the token as a test output;
    if(letter.charAt (0) == 'A') // if letter = A would be ADD
    System.out.println(letter) ;
    buffer = inFile.readLine() ;
         //read in next line
    inFile.close();
    catch (FileNotFoundException e)
    System.out.println("File not found");
    catch ( IOException e)
    System.out.println("IO Exception") ;
    }

    hi,
    i think that what u r tring to do is "parsing" where u translate these primatin=ve commands to execute them, if so here what u need to do:
    Rad a line untell end of file
    for each token in the line
    if(token="SET" || token="ADD || token=""SUB")
    {       //save operation for later use
    operation=token;
    //now u expect the next token to be an operand
    token=nextToken;
    if (token!="" and token!=",")//it must be an operand
    {operand1=token;
    token=next token;
    if(token=",")//do nothing just read the nest operand
    token=nexttoken;
    else //syntax error in file, exit ;
    if (token!="" and token!=",")//checking the 2nd operand
    operand2=token;
    //now check value of operation and call the right method and send operand1,operand2 as arguments to get the result e.g
    if(opration=="ADD")
    system.println("result of addition is"+addMethod(operand1,operand2));
    hope that helps,
    Insighter

  • Getting Buffered Reader to read next line and update.

    Hello.
    I have been trying to get this program to read the next line in a txt file correctly. This is a GUI program
    where clicking the button is supposed to bring up the next bit of information for the user to see.
    I can get the first line of information to come out correctly, but I am unable to get it to read the next line when I click the next button.
    Here is a snippet of my coding...
    private JFileChooser fileChoose;
    private File openedFile;
    private int recordNumber = 0;
    FileReader inFile;
    String sMaker = new String (  );
    else if ( ae.getActionCommand (  ) == "Next Record" )
         if ( openedFile.exists (  ) )
              nextRecord (  );
         else
         JOptionPane.showMessageDialog ( null, "No Files Opened", "No Files Found", JOptionPane.ERROR_MESSAGE );
    public void nextRecord (  )
         recordNumber ++;  // Increment record number
         fileNumber.setText ( sMaker.valueOf ( recordNumber ) );  // Prints to JTextField for user to see
         BufferedReader inText;
         String lineRead;  // Holds line read in
         String [] organizedInfo;  // Array to hold info after being split
         try
              inFile = new FileReader ( openedFile );
              inText = new BufferedReader ( inFile );
              lineRead = inText.readLine (  );
              organizedInfo = ( lineRead.split ( "," ) );//.trim (  );
              for ( int i = 0; i < organizedInfo.length; i ++ )
                   organizedInfo[i] = organizedInfo.trim ( );
    name.setText ( organizedInfo[0] );
    city.setText ( organizedInfo[1] );
    state.setText ( organizedInfo[2] );
    catch ( FileNotFoundException fnfe )
    JOptionPane.showMessageDialog ( null, "Selected File was Not Found", "File Not Found", JOptionPane.ERROR_MESSAGE );
    catch ( IOException ioe )
    JOptionPane.showMessageDialog ( null, "IO Error. Please Try Again.", "IO Error", JOptionPane.ERROR_MESSAGE );
    employee.txt
    William Wallace,Richmond,VA
    Samuel Gompers , San Francisco , California
    Andy Smith,Rochester,NY
    Sandy Beach,Pittsford,NY
    Slim T. None,San Francisco,CA
    George Jones, Washington , D.C.
    Marvin Martin, Boston , Massachusetts
    I. M. Last , Deadmans Gulch, Arizona
    Everytime I click the next button, it should go through the list in employee.txt until i reach the end. But it just stops at William Wallace.
    I know that this can be recoded to make it more efficient, but before that, I still need to figure out how to get the line read to update to next line.
    Thank you in advance.

    Your program works perfectly correctly!
    Each time you click the button it reads the first line and displays it. Why? Because you create a new reader everytime you enter the nextRecord method and the reader reads the first line. Each new reader has no idea where the last reader was upto in your file. It has to start at the beginning.
    <cue response>How do I fix it?

  • Read Registry Keys and store it in Inventory DB

    Hallo together,
    I am looking for a program to extract some Registry keys into the ZENworks 7 inventory database.
    I know I need to create a CUSTOM.INI and fill it with values. When I create the CUSTOM.INI by hand I got it to work to store the values in the inventory database.
    But I need a program to read the Registry values and store them in the CUSTOM.ini file with the correct syntax.
    A Script or any other small program would be helpful. I know how I could read the Registry values with REG.exe but I do not know how to store the values in the correct syntax in CUSTOM.ini?
    I found zRegScan but I did not get it to work. I found out that the Program is called by the Inventory process (it appears in the TaskManager for a short time). When I run zRegScan by hand (or with a manual launched ZfDInvScanner.exe) I get the following error windows:
    Title: zRegScan.exe - Common Language Runtime Debugging Services
    Warning: Application has generated an exception that could not be handled. Process id=0x814, Thread id=0xf14
    When I click "Cancel" I receive a 2nd Window:
    Title: zRegScan.exe - No debugger found.
    Warning: Registered JIT debugger is not available. An atempt to launch a JIT debugger with ...
    I tried for several hours to get it operational - with no success.
    The zRegScan.log does not show anything helpful.
    I have WinXP SP2 and SP3 machines and ZfD7ir3a.
    Thanks for your help
    Klaus

    BachmannK,
    It appears that in the past few days you have not received a response to your
    posting. That concerns us, and has triggered this automated reply.
    Has your problem been resolved? If not, you might try one of the following options:
    - Visit http://support.novell.com and search the knowledgebase and/or check all
    the other self support options and support programs available.
    - You could also try posting your message again. Make sure it is posted in the
    correct newsgroup. (http://forums.novell.com)
    Be sure to read the forum FAQ about what to expect in the way of responses:
    http://forums.novell.com/faq.php
    If this is a reply to a duplicate posting, please ignore and accept our apologies
    and rest assured we will issue a stern reprimand to our posting bot.
    Good luck!
    Your Novell Product Support Forums Team
    http://support.novell.com/forums/

  • I want to change subject line and save emails from others

    For instance my client may respond to an email question and I want to change the subject line because it includes an answer such as clients address, but I cannot figure out how to change the subject line and save it to my file folder I have for them.

    This add on claims to do that.
    https://addons.mozilla.org/en-US/thunderbird/addon/edit-email-subject/?src=ss
    There might be others but that is the first one that came up. I have never used it so I cannot speak for how well it works.

Maybe you are looking for