How to read a particular word from the middle of the line from a .txt file

BufferedReader reader = new BufferedReader(new FileReader("D:\\kiran.txt")); //given as a input
String line = reader.readLine();
StringBuffer sb=new StringBuffer();
while(line!=null){
sb.append(line);//appended to line
line=reader.readLine();
line=sb.toString();
StringTokenizer st=new StringTokenizer(line); //Input to String Tokenizer
while(st.nextToken()!=null){
String ln=st.nextToken();
System.out.println(ln);
if(ln.equals("Time:")){
System.out.println(st.nextToken());
can any help me regarding this

either refer this:-
http://forum.java.sun.com/thread.jspa?threadID=5276606
Or
try this:-
String str=null;
               DataInputStream di=new DataInputStream(new FileInputStream("D:\\Test.txt"));
               while((str=di.readLine())!=null)
                    if(str.contains("Time"))
                         int index=str.indexOf("Time");
                         str=str.substring(index,str.length());
                    System.out.println(str);
               }

Similar Messages

  • How to read Chinese word from a TXT file

    File.OpenText() read a TXT File with  Chinese word in   ;but it not show right.
    exam:The TXT File include :中国
     this.Txt1.Text=ofd.File.OpenText().ReadToEnd();
    but it show :��ʹ�ݼƻ��
    How to solve it

    What encoding does the text file use?  Unlike .NET, Silverlight only supports UTF-8 and UTF-16.  File.OpenText() uses UTF-8 by default.
    If the text file is in some other encoding, you can create your own encoding class (that derives from System.Text.Encoding) that can be used to read the text file.
    class MyEncoding : System.Text.Encoding {
    this.Txt1.Text = (new StreamReader(ofd.File.OpenRead(), new MyEncoding())).ReadToEnd();
    Regards,
    Justin Van Patten
    Program Manager
    Common Language Runtime

  • I can't read in a date from a txt file

    Im not sure of the code needed to read in a date from the text file, this is an example of the text file:
    1
    2
    2003
    ie,
    day
    month year
    I have to read in this date, this is the set method for the date:
    public void setPurchaseDate (int d, int m, int y)
    new Date(d,m,y);
    And this is the code that I have tried using to readin the date:
      PurchaseDate=(Integer.parseInt(line),Integer.parseInt(line),Integer.parseInt(line));now i know its wrong, I just dont know what the code should be!!
    Cheers

    ok, I am going to go through it and see what values I can and cant read in, here is the code i am trying to use:
    private void addx()
           FileReader fin;
           int noBooks;
           int itemNum;
           String title;
           String subject;
           double costNew;
           double costPaid;
           String isbn;
           double sellingPrice = 0;
           int noAuthors;
           int day;
           int month;
           int year;
            String seperator = "#";
            Book[] book = new Book[9];
            try
                fin = new FileReader("Books.txt");
                BufferedReader buff = new BufferedReader(fin);
                String line = buff.readLine();
                int count= 0;
                //read in Number of books
                noBooks=Integer.parseInt(line);
                while( line != null)
                    //Read in item number
                    itemNum = Integer.parseInt(line);
                    //Read in title
                    title = buff.readLine();
                    //Read in number of authors
                    noAuthors=Integer.parseInt(line);
                    //Read each line in as an author until number of authors reached
                    ArrayList authors = new ArrayList();
                    for(int i=0; i < noAuthors ; i++)
                        authors.add(buff.readLine());
                    //Read in cost new
                    costNew = Double.parseDouble(line);
                    //Read in subject
                    subject = buff.readLine();
                    //Read in ISBN
                    isbn = buff.readLine();              
                    //Read in purchase day
                    day = Integer.parseInt(line);
                    //Read in purchase month
                    month=Integer.parseInt (line);
                    //Read in purchase year
                    year = Integer.parseInt (line);
                    //Read in cost paid
                    costPaid = Double.parseDouble(line);
                    line = buff.readLine();
                    //Pass date, month and year values to array
                    Date purchaseDate =new Date(day,month,year);
                    //Pass values to constructor
                    if (line.equals(seperator))
                        book[count++] = new Book(itemNum, title, authors, subject, purchaseDate,costNew,costPaid,isbn, sellingPrice,noAuthors);
                  // line = buff.readLine();
                System.out.println(book.toString());
            catch(Exception ex)
                System.out.println(ex.toString());
             }

  • How to read a particular record from BRF+ table in ABAP

    hi all,
    I have a requirement where a particular record has to be read based on certain value for a set of columns from BRFplus Decision table to Delete/Update. I tried many methods of CL_FDT* but could not find any right one.
    Could anyone please help me?
    Thanks,
    Deepika

    Hi Deepika,
    There is one solution from my side.
    1. Include the Decision table in a BRF+ function.
    2. Set the input and result of the function.
    3. Call the function in the ABAP.
    4. Get the record from result.
    Please find the call function logic in ABAP as below.
    Data:
            lo_admin_data         TYPE REF TO if_fdt_admin_data,
            lo_function           TYPE REF TO if_fdt_function,
            lo_context            TYPE REF TO if_fdt_context,
            lo_result             TYPE REF TO if_fdt_result.
    cl_fdt_factory=>get_instance_generic( EXPORTING iv_id = "functon id in general tab"
                                                          IMPORTING eo_instance = lo_admin_data ).
    lo_function ?= lo_admin_data.
    *Set input parameter
    lo_context ?= lo_function->get_process_context( ).
    lo_context->set_value( iv_name = "parameter name"    ia_value ="parameter value" ).
    lo_function->process( EXPORTING io_context = lo_context
                                              IMPORTING eo_result = lo_result ).
    lo_result->get_value( IMPORTING ea_value = "Result" ).
    Best Regards
    Clark Huang

  • How to read sampled data info from a "*.au"file into an array?

    I need to manipulate the sound file directly using DSP, the first step is to read sampled data from "*.au" file into an array. How can I do that? Thanks a lot!!

    There is a file I/O tutorial in the Java Tutorial (google for Java Tutorial). You can read an .au file as bytes like any binary file.
    Or if you are using the Java Sound API, google for java sound api or java audio tutorial etc etc.

  • Urgent: How to exclude a particular value from the selection in the infopac

    How to exclude a particular value from the selection in the infopackage.
    Ex: not load for cost center 10000
    Thank you,
    sam

    Hi Sam,
    You cannot do this directly as exclusion, but you can include all other values, even as ranges and thus exclude the particular value, else you can also try to do this by writing a routine.
    Hope this helps...

  • Code for how to read an integer array from the command prompt...

    hello,
    Could anyone give me the code for how to read an integer array from the command prompt...its very urgent!..

    If you are using a recent version of Java (5 or later) you can use Scanner:
    http://java.sun.com/javase/6/docs/api/java/util/Scanner.html
    That page has some example code on it, too.

  • How to calculate the number of vowels from a txt file. Pls give me a hand!!

    Guys! How do i calculate the number of vowels from a txt file? I have to create a program to count the number of words, sentence, and vowels. So far I had managed to count the number of words. Now I need help on counting sentence and vowels! Pls give me a hand guys!

    I first have to read from the file not the string.I
    know how to read from a file. Now the problem ishow
    to compare a character from a txt file!You fail to understand, that you have read the data
    from the file into a string. Now loop over all
    characters in the string. Forget about the file.
    KajOr forget the scanners just as others have told you. Just read the file character by character using a FileReader.
    Kaj

  • How to find a particular word in a file using java

    Program how to find a particular word in a file

    SirivaniG wrote:
    Program how to find a particular word in a fileOkay, I finished it. Now what?

  • Populate a table reading the data from a TXT file

    how can I populate a table reading the data from a TXT file?
    thanks

    Hey Kevin!
    Using FORMS.TEXT_IO to bulk load data from a file strikes me as re-inventing the wheel. It is just about justifiable in a self-service environment, but I regard the EXTERNAL TABLE is a better solution for that situation as well.
    The same applies to UTL_FILE. I think the ability to read text with UTL_FILE is primarily intended for read file-based configuration or file manipulation/processing rather than data loading.
    Re-writing a text file into SQL statements is too much like hard work (even with an editor that supports macro definition and regular expressions) for no real benefit. You lose all the bulk load peformance you would get from SQL*Loader. But for QAD I'd probably let you off with it.
    You missed out one obvious alternative: using Java to turn the contents of an XML file into a CLOB and inserting it into a table which is read by a PL/SQL procedure that parses the XML records and insert the retrieved data into a table.
    Stay lucky, APC

  • How to read the last line in a txt file?

    Dear all,
    I want to read the last line in a txt file. There are thousands of lines in this file. What I want is to move the file pointer directly to the last line of the file. But I did not know how do to it. Can anybody help me out?
    Thank you very much!

    If the file is coded as ASCII or one of the encodings that maps a single byte to a char then the following class will assist you
    import java.io.*;
    import java.util.*;
    public class GetLinesFromEndOfFile
        static public class BackwardsFileInputStream extends InputStream
            public BackwardsFileInputStream(File file) throws IOException
                assert (file != null) && file.exists() && file.isFile() && file.canRead();
                raf = new RandomAccessFile(file, "r");
                currentPositionInFile = raf.length();
                currentPositionInBuffer = 0;
            public int read() throws IOException
                if (currentPositionInFile <= 0)
                    return -1;
                if (--currentPositionInBuffer < 0)
                    currentPositionInBuffer = buffer.length;
                    long startOfBlock = currentPositionInFile - buffer.length;
                    if (startOfBlock < 0)
                        currentPositionInBuffer = buffer.length + (int)startOfBlock;
                        startOfBlock = 0;
                    raf.seek(startOfBlock);
                    raf.readFully(buffer, 0, currentPositionInBuffer);
                    return read();
                currentPositionInFile--;
                return buffer[currentPositionInBuffer];
            public void close() throws IOException
                raf.close();
            private final byte[] buffer = new byte[4096];
            private final RandomAccessFile raf;
            private long currentPositionInFile;
            private int currentPositionInBuffer;
        public static List<String> head(File file, int numberOfLinesToRead) throws IOException
            return head(file, "ISO-8859-1" , numberOfLinesToRead);
        public static List<String> head(File file, String encoding, int numberOfLinesToRead) throws IOException
            assert (file != null) && file.exists() && file.isFile() && file.canRead();
            assert numberOfLinesToRead > 0;
            assert encoding != null;
            LinkedList<String> lines = new LinkedList<String>();
            BufferedReader reader= new BufferedReader(new InputStreamReader(new FileInputStream(file), encoding));
            for (String line = null; (numberOfLinesToRead-- > 0) && (line = reader.readLine()) != null;)
                lines.addLast(line);
            reader.close();
            return lines;
        public static List<String> tail(File file, int numberOfLinesToRead) throws IOException
            return tail(file, "ISO-8859-1" , numberOfLinesToRead);
        public static List<String> tail(File file, String encoding, int numberOfLinesToRead) throws IOException
            assert (file != null) && file.exists() && file.isFile() && file.canRead();
            assert numberOfLinesToRead > 0;
            assert (encoding != null) && encoding.matches("(?i)(iso-8859|ascii|us-ascii).*");
            LinkedList<String> lines = new LinkedList<String>();
            BufferedReader reader= new BufferedReader(new InputStreamReader(new BackwardsFileInputStream(file), encoding));
            for (String line = null; (numberOfLinesToRead-- > 0) && (line = reader.readLine()) != null;)
                // Reverse the order of the characters in the string
                char[] chars = line.toCharArray();
                for (int j = 0, k = chars.length - 1; j < k ; j++, k--)
                    char temp = chars[j];
                    chars[j] = chars[k];
                    chars[k]= temp;
                lines.addFirst(new String(chars));
            reader.close();
            return lines;
        public static void main(String[] args)
            try
                File file = new File("/usr/share/dict/words");
                int n = 10;
                    System.out.println("Head of " + file);
                    int index = 0;
                    for (String line : head(file, n))
                        System.out.println(++index + "\t[" + line + "]");
                    System.out.println("Tail of " + file);
                    int index = 0;
                    for (String line : tail(file, "us-ascii", n))
                        System.out.println(++index + "\t[" + line + "]");
            catch (Exception e)
                e.printStackTrace();
    }Note, the EOL characters are treated as line separators so you will probably need to read the last two lines (think about it for a bit).

  • How can I add a word to the dictionary?

    How can I add a word to the dictionary on my iPhone 6 plus?
    Thanks.

    There's not an option to add a word to the dictionary. However, after typing that word several times, it will start to recognize it and offer it as a suggested word.

  • HT5463 how i can block particular number from my contacts list

    how i can block particular number from my contacts list please guide me because even true caller software is also not supporting iphone

    As Ocean20 said, there is no official function that does this built in. What you could do however is to find an app that mute calls that come from "blocked" numbers.

  • How to edit a particular row in the table ctrl when a push button is clickd

    Hi Experts,
    How to edit a particular row (except the Primary keys) after selecting it in the TABLE CONTROL when a
    push button is clicked in the table control.
    For Eg. If you have a push button say "Modify", the particular row what we select in the table control should be in a
    editable mode after clicking "Modify" Push button.
    Please help me out.
    Thanks in advance.

    Hey Ram,
    Thanks a ton.
    Its working fine...sorry for the late reply.
    The reason behind the delay is because i had modified my code as per your logic it worked fine but the thing is that the whole column was in editable mode but not a single row.
    For E.g  If i want to edit a particular row, first i select the row and then  click on "Modify" button. After i click on the button, the whole column gets in a editable mode including the one which i intentionally selected.
    Here, the solution is that you have to set a flag in PBO so that once it is done with PBO then it need not come back again after we click on "Modify" button.
    And one more query is that after you modify a particular row in the table control ( When it is in editable mode) and click on the "Save" button, it is not getting updated to database.
    To update the database, we need to select the row once again after modifying it and click on the "Save" button.
    Here, database is updating only when it is selected again. If it is not selected, it is not getting updated.
    If you have any alternative solution, then please help me out.( I hope i am clear with the question.)
    Thanks,
    Ananth.

  • How to remove a particular gadget from windows7 image

    sir how to remove a particular gadget from all other existing gadgets in windows 7sp1 image, can we do it by DISM?

    Hi,
    If the above method doesn't work, you can try pre-configuring sidebar gadgets using unattend.xml, which can be used to override Sidebar default settings.
    To disable Windows sidebar gadgets when windows load, you can configure this following in your unattend.xml.
    <unattend xmlns="urn:schemas-microsoft-com:unattend" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State">
    <settings pass="oobeSystem">
    <component name="Microsoft-Windows-Sidebar" publicKeyToken="31bf3856ad364e35" language="neutral"
    versionScope="nonSxS" processorArchitecture="x86">
    <SidebarOnByDefault>false</SidebarOnByDefault>
    </component>
    </settings>
    </unattend>
    For detailed information, you can refer to
    http://blogs.msdn.com/b/sidebar/archive/2007/03/08/pre-configuration-of-sidebar-gadgets-using-unattend-xml.aspx
    Or try customize windows using sysprep tool
    http://www.sevenforums.com/tutorials/286053-system-preparation-tool-use-customize-windows.html
    Andy Altmann
    TechNet Community Support

Maybe you are looking for

  • Receipts & Payment report for a particular period

    Dear Team, PFA of receipts & payment report which has to be executed in SAP without development. Kindly request to check & suggest. Thanks & Regards, Sai

  • SAP E-Commerce 5.0 - SAP Internet Sales (R/3) Edition - WebIOException

    When choosing the same item from the catalog twice and proceeding to order we are getting a runtime error. In the logs we can see the error detail below: application [] Error in finalizing PageContext.  The error is: com.sap.engine.services.servlets_

  • Table of Content Help - Anchored Objects/Listing Order

    For the love of god this is extremely frustrating.   I have been searching for literally hours trying to find the solution. I have a large document, linked frames from page 1 through page 44 for example. On many pages I have figures, and using an inc

  • Problem using book reader

    I went to settings and turned on speak screen in settings, and then two finger swiped down on book page.  I finally got it to start speaking and got the controls with speeds etc.  Then I mistakenly clicked the X - close controls on R. (instead of the

  • Accrual and deferal

    Hi experts, Can any body explain the theoritical concept of Accrual and deferal entries. When these can be posted in FBs1 and what is the need to reverse at any particular day in f.81 Regards: Dasu