Find exact word in text file tht is present in an excel sheet

Hi all,
i want to find words in an text file.
but the criteria is i want to search words which r already listed in another excel sheet and change the color of these word.
i used FileInputStream
and also BufferedInputStream
cany anyone help me with this

hi kajbj,
can u plz tell me how to do in VBA then
will find out the way to do in java
Thanx

Similar Messages

  • Identifying text file names and importing on single Excel sheet

    Hey!
    Does anybody can help me with Excel VBA macro code in order to import data from text files into single Excel spread sheet? I want to create User Form where user can select start and end date of interest and macro code will import
    bunch of text files depending on user demands...
    My text files are named: 20130619004948DataLog.txt (meaning: yyyy mm dd hh mm ss). Text file contains recordings for each 15 seconds... It would be great to omit time tail (meaning that user can only specify date). Text files for one day of interest (I have
    text files covering whole year):
    20130619004948DataLog.txt
    20130619014948DataLog.txt
    20130619024948DataLog.txt
    20130619034948DataLog.txt
    20130619044948DataLog.txt
    20130619054948DataLog.txt
    20130619064948DataLog.txt
    20130619074948DataLog.txt
    20130619084948DataLog.txt
    20130619094948DataLog.txt
    20130619104948DataLog.txt
    20130619114948DataLog.txt
    20130619124948DataLog.txt
    20130619134948DataLog.txt
    20130619144948DataLog.txt
    20130619154948DataLog.txt
    20130619164948DataLog.txt
    20130619174948DataLog.txt
    20130619184948DataLog.txt
    20130619194948DataLog.txt
    20130619204948DataLog.txt
    20130619214948DataLog.txt
    20130619224948DataLog.txt
    20130619234948DataLog.txt
    Option Explicit
    Sub SearchFiles()
    Dim file As Variant
    Dim x As Integer
    Dim myWB As Workbook
    Dim WB As Workbook
    Dim newWS As Worksheet
    Dim L As Long, t As Long, i As Long
    Dim StartDateL As String
    Dim EndDateL As String
    Dim bool As Boolean
    bool = False ' to check if other versions are present
    StartDateL = Format(Calendar1, "yyyymmdd")
    EndDateL = Format(Calendar2, "yyyymmdd")
    ' I am using Userform asking user to select the date and time range of interet,
    ' However, I want to use only the date to filter the files having the name with that particular date
    file = Dir("c:\myfolder\") ' folder with all text files
    ' I need assistance with the following part:
    '1) How to filter and select the files between StartDateL and EndDateL_
    '(including files with that dates as well)?
    While (file <> "")
    If InStr(file, StartDateL) > 0 Then 'Not sure if the statements inside parenthesis is correct
    bool = True
    GoTo Line1:
    End If
    file = Dir
    Wend
    Line1:
    If Not bool Then
    file = "c:\myfolder\20130115033100DataLog.txt" 'Just for a test that the code works as intended
    End If
    'This part for the selected text files to be loaded on a single Excel Sheet.
    Set myWB = ThisWorkbook
    Set newWS = Sheets(1)
    L = myWB.Sheets(1).Cells(Rows.Count, "A").End(xlUp).Row
    t = 1
    For x = 1 To UBound(file)
    Workbooks.OpenText Filename:=file(x), DataType:=xlDelimited, Tab:=True, Semicolon:=True, Space:=False, Comma:=False
    Set WB = ActiveWorkbook
    WB.Sheets(1).UsedRange.Copy newWS.Cells(t, 2)
    t = myWB.Sheets(1).Cells(Rows.Count, "B").End(xlUp).Row + 1
    WB.Close False
    Next
    myWB.Sheets(1).Columns(1).Delete
    Application.ScreenUpdating = False
    Rows("1:1").Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
    End Sub

    - Make a new Excel file
    - Open the VBA editor
    - Add a Userform
    - Place 2 text boxes and 1 command button on that form
    - Paste all code below into the code module of the form
    - Download this file:
    https://dl.dropboxusercontent.com/u/35239054/FileSearch.cls
    - In the VBA editor press CTRL-M and import that file
    - Save the Excel file in the directory that contain your text files
    - Run the form
    You can format the columns of the sheet as you like, e.g. column E:H should be a number with 5 decimal places. The top row can contain some headings. My code did not affect the formatting or the headings.
    Andreas.
    Option Explicit
    Private Sub UserForm_Initialize()
    'Just a sample
    Me.TextBox1.Value = FormatDateTime(Now, vbGeneralDate)
    Me.TextBox2.Value = FormatDateTime(Now, vbShortDate)
    End Sub
    Private Sub CommandButton1_Click()
    Dim StartDate As Date, EndDate As Date
    Dim FS As New FileSearch
    Dim R As Range
    Dim ThisFile As Variant
    Dim ThisDate As Date
    Dim Data As Variant
    Dim Count As Long
    'Be sure we have 2 dates
    If Not IsDate(Me.TextBox1.Value) Then
    Me.TextBox1.SetFocus
    MsgBox "No start date"
    Exit Sub
    End If
    If Not IsDate(Me.TextBox2.Value) Then
    Me.TextBox2.SetFocus
    MsgBox "No end date"
    Exit Sub
    End If
    'Convert to real dates
    StartDate = CDate(Me.TextBox1.Value)
    EndDate = CDate(Me.TextBox2.Value)
    'Time part given?
    If Fix(EndDate) = EndDate Then
    'No include all files for this day
    EndDate = EndDate + TimeSerial(23, 59, 59)
    End If
    'Correct order?
    If StartDate > EndDate Then
    ThisDate = EndDate
    EndDate = StartDate
    StartDate = ThisDate
    End If
    With FS
    'Same path as our file
    .LookIn = ThisWorkbook.Path
    .FileName = "*DataLog.txt"
    'Search all files sort by file name
    If .Execute(msoSortByFileName, msoSortOrderAscending) = 0 Then
    MsgBox "No data files found in " & .LookIn
    Exit Sub
    End If
    'Clear previous data
    Set R = Range("A2").CurrentRegion
    If R.Row < 2 Then Set R = R.Offset(1)
    R.ClearContents
    'Show the user that we are working
    Application.Cursor = xlWait
    DoEvents
    For Each ThisFile In .FoundFiles
    'Get the date from the file name
    ThisDate = Filename2Date(ThisFile)
    'Between our dates?
    If (ThisDate >= StartDate) And (ThisDate <= EndDate) Then
    'Import at the end of the data
    Set R = Range("A" & Rows.Count).End(xlUp).Offset(1)
    Data = ReadCSV(ThisFile)
    R.Resize(UBound(Data) + 1, UBound(Data, 2) + 1) = Data
    Count = Count + 1
    End If
    Next
    End With
    'Done
    Application.Cursor = xlDefault
    If Count = 0 Then
    MsgBox "No files match your dates"
    Else
    MsgBox Count & " files imported"
    'Hide the form
    Me.Hide
    End If
    End Sub
    Private Function Filename2Date(ByVal Fullname As String) As Date
    'Convert e.g "C:\20130601142648DataLog.txt" to the date "01.06.2013 14:26:48"
    Dim i As Long, j As Long
    i = InStrRev(Fullname, "\")
    If i > 0 Then Fullname = Mid(Fullname, i + 1)
    Fullname = JustNumbers(Fullname)
    If Len(Fullname) <> 14 Then Exit Function
    Filename2Date = _
    DateSerial(Mid(Fullname, 1, 4), Mid(Fullname, 5, 2), Mid(Fullname, 7, 2)) + _
    TimeSerial(Mid(Fullname, 9, 2), Mid(Fullname, 11, 2), Mid(Fullname, 13, 2))
    End Function
    Private Function JustNumbers(ByVal What As String) As String
    'Return only numbers from What (by Rick Rothstein)
    Dim i As Long, j As Long, Digit As String
    For i = 1 To Len(What)
    Digit = Mid$(What, i, 1)
    If Digit Like "#" Then
    j = j + 1
    Mid$(What, j, 1) = Digit
    End If
    Next
    JustNumbers = Left$(What, j)
    End Function
    Private Function ReadCSV(ByVal Fullname As String) As Variant
    'Read a CSV file into an array
    Const LDelim = vbCrLf 'Line delimiter
    Const FDelim = ";" 'Field delimiter
    Dim hFile As Integer
    Dim Buffer As String
    Dim Lines, Line, Data
    Dim i As Long, j As Long
    'Be sure the file exists
    If Dir(Fullname) = "" Then Exit Function
    'Open and read all data
    hFile = FreeFile
    Open Fullname For Binary Access Read As #hFile
    Buffer = Space(LOF(hFile))
    Get #hFile, , Buffer
    Close #hFile
    'Split into lines
    Lines = Split(Buffer, LDelim)
    'Split the first line and prepare the output
    'Note: I assume that all lines have the same number of fields
    Line = Split(Lines(0), FDelim)
    ReDim Data(0 To UBound(Lines), 0 To UBound(Line))
    For i = 0 To UBound(Lines)
    Line = Split(Lines(i), FDelim)
    For j = 0 To UBound(Line)
    'Parse the fields
    If IsDate(Line(j)) Then
    Data(i, j) = CDate(Line(j))
    ElseIf IsNumeric(Line(j)) Then
    Data(i, j) = CDbl(Line(j))
    Else
    Data(i, j) = Line(j)
    End If
    Next
    Next
    ReadCSV = Data
    End Function

  • Find word in text file and count specific words

    now I'll try to explain what I need to do. I have file.txt file, It looks like:
    John //first line - name
    One
    Three
    Four
    Peter //first line - name
    Two
    Three
    Elisa //first line - name
    One
    Three
    Albert //first line - name
    One
    Three
    Four
    Nicole //first line - name
    Two
    FourSo I have program's code:
    public class Testing {
            public static void main(String args[]) throws Exception {
                Scanner input = new Scanner(System.in);
                System.out.println("Select word from list:");
                System.out.println();
                try {
                    FileReader fr = new FileReader("src/lt/kvk/i3_2/test/List.txt"); // this is list of words, everything all right here
                    BufferedReader br = new BufferedReader(fr);
                    String s;
                    while((s = br.readLine()) != null) {
                        System.out.println(s);
                    fr.close();
                    String stilius = input.nextLine();   // eneter word which I want to count in File.txt
                    BufferedReader bf = new BufferedReader(new FileReader("src/lt/kvk/i3_2/test/File.txt")); // from this file I need to count word which I entered before
                    int counter = 0;               
                    String line;
                    System.out.println("Looking for information");
                    while (( line = bf.readLine()) != null){
                        int indexfound = line.indexOf(stilius);
                        if (indexfound > -1) {
                             counter++;
                    if (counter > 0) {
                        System.out.println("Word are repeated "+ counter + "times");}
                        else {
                        System.out.println("Error...");
                    bf.close();
                catch (IOException e) {
                    System.out.println("Error:" + e.toString());
            }This program counting specific word (entered by keyboard) in file.txt.
    I need to make this program: for ex.: if I enter word: One It must show:
    Word One repeated 3 times by John, Elisa, AlbertAll what I need to elect by who this word repeated. But I don't know really how to make It, maybe LinkedList or I dont know, someone could help me?
    Thank you very much.

    966676 wrote:
    All what I need to elect by who this word repeated. But I don't know really how to make It, maybe LinkedListYou should choose the simplest type fullfilling your needs. In this case I'd go for <tt>HashSet</tt> or <tt>ArrayList</tt>.
    or I dont know, someone could help me?You need to introduce a variable to store the actual name which must be resetted if an empty line is found and then gets assigned the verry next word in the file.
    bye
    TPD

  • Finding strings in a text file?

    Hi! i'm learning to read text files. what i want to do with this program is to find word 1-3, 2-4, 3-5... and write them in a system.out.println. i found a program that opens files and count words, lines and characters and tried to adjust it do find three-word strings.
    i can compilate (hope that word exists) but when i run it, it says: Exception in thread "main" java.lang.NoSuchMethodError: main
    anyone who knows what this could depend on?
    This is what the code looks like:
    import java.io.*;
    import java.io.*;
    import java.util.*; //tillagd f�r att removeFirst4 skall funka
    import javax.swing.*; //tillagd f�r att removeFirst4 skall fungera
    import java.util.regex.Pattern;
    import java.util.regex.Matcher;
    import java.lang.*;
    import javax.swing.*;
    public class AttLaesaEnFil2 {
         private static void samla(String name, BufferedReader in) throws
         IOException {
         String a;
         WordExtractor b;
    String c = " ";
    String d;
    WordExtractor e;
    String f;
    String g;
    WordExtractor h;
    String i;
    String j;
    String k;
    String l;
    String line;
    do {
                   line = in.readLine();
                   if (line != null)
    b = new WordExtractor(line);
         c = b.getFirst();
         d = b.getRest();
         e = new WordExtractor(d);
         f = e.getFirst();
         g = e.getRest();
         h = new WordExtractor(g);
         i = h.getFirst();
         j = h.getRest();
         k = c + f + i;
         l = c + " " + f + " " + i;
         System.out.println("The first three words are: " + l);
         a = b.getRest();
    while (line != null);
              System.out.println("Klart!");
              private static void samla(String fileName) {
              BufferedReader in = null;
              try {
                   FileReader fileReader = new FileReader(fileName);
                   in = new BufferedReader(fileReader);
                   samla(fileName, in);
              } catch (IOException ioe) {
                   ioe.printStackTrace();
              } finally {
                   if (in != null) {
                        try {
                             in.close();
                        } catch (IOException ioe) {
                             ioe.printStackTrace();
         private static void samla(String streamName, InputStream input) {
              try {
                   InputStreamReader inputStreamReader = new InputStreamReader(input);
                   BufferedReader in = new BufferedReader(inputStreamReader);
                   samla(streamName, in);
                   in.close();
              } catch (IOException ioe) {
                   ioe.printStackTrace();
    Thanx in advance!

    this may be a stupid question but i'll give it a
    shot. ...do i replace my private static void with
    public static void or do a add the public?Whether you replace one of your methods or create a new one is up to you, but you have to have a method with this exact signature:
    public static void main(String[] foo) {
    }(The variable name can be different of course)

  • Seachring word from text file

    Hi...There..
    I h'va wrirtten Search application which search words from Simple text files.
    My file contains list of words separated by "\n"(new line).
    i am using java.io.BufferedReader for reading file.
    i'want to search word from file within few milliseconds, but when my file containo more then some 2lake words(200000) my process of readind comsumes more then 5 sec. time to search.
    pl. suggest me effective method to search word from file so i can make it rapid search.
    Actually i 've to provide search on "TEXT VALUE CHANGED EVENT" so even if my process takes more then one seconds it is not physible for me.
    Thanks in Advance.
    Timir Patel.

    Try this:
    import java.io.*;
    import java.util.*;
    public class searcher
              private static long [] indexes;
         private static class temp_data
              public final String text;
              public final long starts_at;
              public temp_data(String t, long l)
                   text = t;
                   starts_at = l;
         private static class temp_cmp implements Comparator
              public int compare(Object o1,Object o2)
                   return ((temp_data)o1).text.compareTo(
                             ((temp_data)o2).text);
         /** creats index table. You should do it once, and rather store index
         table in file then. This method has high peak memory usage but it is
           easy to optimize it.*/
         private static void buildIndex(RandomAccessFile file)throws Exception
              List temp = new LinkedList();
              String st;
              long p = file.getFilePointer();
              while((st = file.readLine())!=null)
                   temp.add(
                        new temp_data(st,p)
                   p = file.getFilePointer();
              Collections.sort(temp,new temp_cmp());
              indexes = new long[temp.size()];
              int i=0;
              for(Iterator I=temp.iterator();I.hasNext();i++)
              temp_data tt = ((temp_data)I.next());
               System.out.println("indexing :"+tt.text+" ["+tt.starts_at+"]");
                   indexes=tt.starts_at;
         /** returns position at which text starts or -1 if not found */
         public static long find(String text,RandomAccessFile file)throws Exception
              int ncp = indexes.length/2;
              int n = 2;
              int cp;
              do{
              cp = ncp;
                   file.seek(indexes[cp]);
                   String tt = file.readLine();
              System.out.println("comparing with "+tt);
                   int cmpr = text.compareTo(tt);
                   if (cmpr==0)
                        return indexes[cp];
                   else
                   if (cmpr>0)
                        ncp = cp+(indexes.length / (1<<n));
                   else
                        ncp = cp-(indexes.length / (1<<n));
                   n++;
              }while(ncp!=cp);
              return -1;
         public static void main(String args [] )throws Exception
              RandomAccessFile f = new RandomAccessFile(args[0],"r");
              buildIndex(f);
              for(int i=1;i<args.length;i++)
              System.out.println("searching for \""+args[i]+"\"");
              System.out.println("found at:"+find(args[i],f));
              f.close();
    It should work, however I gave it less than five minutes testing.

  • Find Change through external text file

    Hello folks
    I am bit pretty in InDesign scripting so could you please look into this.
    How can i change any particular text field in Indesign CS3 document from text file.
    I do have find change script but for each InDesign document specific text file is assigned.
    So each time i have to modify find change GREP property that is also repetetive of work. Is there any way to get find change information should be extract from external text file.
    Many Tanks in advance

    In the FindChangeByList script, you could customize the function myFindFile(myFilePath) {...} as to search the FindChangeList text file in the document location rather than the script location. That's an example. The question is: given a document, where will you have the corresponding FindChangeList?
    @+
    Marc

  • How to find largest number from text file

    I am using the "Read from text file" block to read the data from my .txt file into labview.  It is now in string format.  I have many numbers in the file.  
    For example:
    0.45
    0.35
    0.12
    1.354
    1.56
    2.89
    5.89
    0.56
    That is what a text file might look like.  I want to find which of these numbers is largest, and do calculations with that number.  I am having trouble with strings/number formats/arrays, etc.  Thanks
    Solved!
    Go to Solution.

    The spreadsheet functions and VIs typically work on strings representing numbers separated by delimiters.  This is a typical way to save a "spreadsheet" (of numbers) to a text file, for example .csv files.  These are quite versatile and powerful functions.  Spend a bit of time becoming familiar with them because you may find yourself using them a lot.
    Lynn

  • Read a non english word from text file

    While Reading thai charater from text file which was sent by QAD(a different application),
    We are reading 60 char using substr() function.
    If the data is English word it reads correctly with 60 char.
    But if it is in thai characters it returns more than 60 char.
    In oracle all NLS Char set has been already set.
    Can anyone help in this issue
    thanks in advance

    Maybe you should use SUBSTRC, SUBSTR2 or SUBSTR4 depending on the character set of your database. See http://download-uk.oracle.com/docs/cd/B10501_01/server.920/a96540/functions119a.htm#87068
    Message was edited by:
    Pierre Forstmann

  • Reading first word from text file

    Hello all,
    I created a program which I can type in a line and store it into a file. What I need my next program to do is read and display just the first word from each line on the text file.
    Here is what I have:
    import java.io.*;
    public class ReadFromFile
    public static void main (String args[])
         FileInputStream firstWord;          
              try
                  // Open an input stream
                  firstWord = new FileInputStream ("FileofWords.txt");
                  // Read a line of text
                  System.out.println( new DataInputStream(firstWord).readLine() );
                  // Close our input stream
                  firstWord.close();          
                   System.err.println ("Unable to read from file");
                   System.exit(-1);
    }

    what i would like is my program to get the first word of every line and put it in my array.
    This is what i have attempted.
    import java.io.*;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.io.BufferedReader;
    public class testing {
         String[] tmp = new String [2];
         String str;
         public void programTest()
              try
                             BufferedReader in2 = new BufferedReader(new FileReader("eventLog.log"));
                             while ((str = in2.readLine()) != null)
                                  tmp = str.split(" ");
                                  System.out.println(tmp[0]);
                        catch(IOException e)
                             System.out.println("cannot read file");
    public static void main(String[] args)
                 testing B = new testing();
                 B.programTest();
    }//end classAny help is most appreciated

  • Search word in text file

    Hello,
    someone can help me with code?
    How to search in text file any word and count how many it were repeated?
    For example test.txt:
    hi
    hola
    hey
    hi
    bye
    hoola
    hiAnd if I want to know how many times are repeated in test.txt word "Hi" program must say "3 times repeated"
    I hope you understood what I want, thank you for answers.

    This is my code now.
    package lt.kvk.i3_2.test;
    import java.io.BufferedReader;
    import java.io.FileReader;
    import java.io.IOException;
    import java.util.Scanner;
    public class Testing {
              public static void main(String args[]) throws Exception {
                   Scanner input = new Scanner(System.in);
                System.out.println("Select word from list:");
                System.out.println();
                try {
                        FileReader fr = new FileReader("src/lt/kvk/i3_2/test/List.txt"); // this is list of words, everything all right here
                        BufferedReader br = new BufferedReader(fr);
                        String s;
                        while((s = br.readLine()) != null) {
                             System.out.println(s);
                        fr.close();
                        String stilius = input.nextLine();   // eneter word which I want to count in File.txt
                    BufferedReader bf = new BufferedReader(new FileReader("src/lt/kvk/i3_2/test/File.txt")); // from this file I need to count word which I entered before
                    int counter = 0;               
                    counter = counter + 1;
                    counter++;
                    counter += 1;
                    String line;
                    System.out.println("Looking for information");
                    while (( line = bf.readLine()) != null){
                    int indexfound = line.indexOf(stilius);
                    if (indexfound > -1) {
                    System.out.println( "At all words which You want to count are "+ counter);
                    bf.close();
                catch (IOException e) {
                    System.out.println("Error");
              }         Here example of file.txt:
    test
    tea
    tree
    test
    car
    wind
    dog
    test
    car
    sea
    tea
    testIf I enter for example word "test" or any from this list I got answer:
    Looking for information
    At all words which You want to count are 3But it must to count how many times in this file this word are repeated, it must be 4
    if I enter word car It must show 2....
    And if I enter word which isn't in list (file.txt)
    Program didn't show error, just:
    Looking for informationThanks for answers.

  • Read words from text file by delimiter as columns and rows

    Hi All,
    I need your help as i have a problem with reading string by delimiter. i have used various tech in java, but i can not get the result as expected.
    Please help me to get the string from text file and write into excel . i have used a text file.
    problem
    get the below as string by delimiter
    OI.ID||'|'||OI.IDSIEBEL||'|'||OI.IDTGU||'|'||OI.WORKTYPE||'|'||OI.UTR_FK
    read the below as string by delimiter
    "50381|TEST_7.15.2.2|09913043548|Attivazione|07-SEP-10
    now i need to write the above into excel file as columns and rows.
    there are 5 columns and each corresponding values
    the outut excel should be
    OI.ID OI.IDSIEBEL OI.IDSIEBEL OI.WORKTYPE OI.UTR_FK
    50381 TEST_7.15.2.2 09913043548 Attivazione 07-SEP-10
    i tried in diffrerent techinq but not able to get the resule. pls help me
    Thanks,
    Jasmin
    Edited by: user13836688 on Jan 22, 2011 8:13 PM

    First of all, when posting code, put it between two tags.
    Second of all, the pipe is a special character in regex, so you need to escape it as
    .split("\ \|");
    Erh. So 2 backslashes before the pipe character. Stupid forum won't post it.
    Edited by: Kayaman on Jan 24, 2011 9:35 AM
    Edited by: Kayaman on Jan 24, 2011 9:35 AM
    Edited by: Kayaman on Jan 24, 2011 9:36 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • When I import a text file(comma separated )into a numbers spread sheet all the data goes into one column. Why does the text not go into separate columns based on the commas.

    When I import a text file(comma separated) into a numbers spreadsheet all the data goes into one column instead of individual columns based on the comma separators.  Excel allows you to do this during the import..  Is there a way to accomplish this in numbers without opening it in Excel and the importing into Numbers.

    Your user info says iPad. This is the OS X Numbers forum. Assuming you are using OS X… Be sure the file is named with a .csv suffix.
    (I don't have an iPad, so I don't know the iOS answer.)

  • Find line number in text file

    Hi all,
    I need to find the line numbers on a file where a particular string matches.
    for example:
    A lazy cat
    A strong cat and it is black
    Black is not good
    So I will match for the word black and it will give the numbers say line 2 and 3 it found the match.
    I am using the code:
    try{
        // Open the file that is the first
        // command line parameter
          FileInputStream fstream = new FileInputStream("c:\\test.log");
        // Get the object of DataInputStream
          DataInputStream in = new DataInputStream(fstream);
          BufferedReader br = new BufferedReader(new InputStreamReader(in));
          String strLine;
         String[] arr= null;
        //Read File Line By Line
       String regex = "black";
       while ((strLine = br.readLine()) != null)   {
        // Split the sentence into strings based on space
           arr = strLine.split("\\s");
       if (arr[0].equalsIgnoreCase("black"))
          System.out.print("match found");
        Pattern p = Pattern.compile(regex);
        Matcher m = p.matcher(strLine);Thanks in advance.

    camellia wrote:
    I need to find the line numbers on a file where a particular string matches. Then declare a variable for line count. Find where you read in a line. Finally increment this variable each time a line is read.
    It isn't rocket science.
    Mel

  • Browser can't find a text file opened via the save as dialogue box

    Hi there,
    I have a servlet which outputs a file using the servlet output stream, with the following lines set:
    response.setContentType("application/msword");
    response.setHeader("Content-Disposition", "attachement; filename="+ fileName);
    servletOutStream.write(myBytes);
    servletOutStream.flush();
    It works fine for .doc files and it seems the mechanism is that it is saved to the Temporary Internet Folder and delivered from there when the user clicks on the 'open' or 'save' option in the browser popup dialogue box. However... when I try this with text files, (setting the content type to "text/plain") I get the open/save dialogue box up correctly but if I try to open the file it says it cannot find the file, and gives the path under the Temporary Interenet Folder. If I look in there the text file isn't present - though the .doc files are.
    So... it looks as if the problem is that for some reason it doesn't save the text files correctly to the Temporary Internet Folder.
    I can't deliver the text files inline as a solution as the filename is lost and it thinks it's an html file (which the client doesn't want).
    Any ideas?
    Alison

    At least also set the content length. Your browser may be configured be the default application to open textfiles. If the contentlength is not set, then most applications would refuse to open the file without choosing for 'Save' first and manually open it.

  • Read words from a text file into an undefined array

    Dear all,
    Does anyone know how to read words in text file, seperated by all types of spaces ("_", "\n", "\t","\r","\f") and put them into a string array to be used later?
    So far I can read the words using the Tokenizer but can't assign to array:
    public class reader
    StringTokenizer tokenizer = new StringTokenizer(input);
    String[ ] array= null;  //unknown size of array
    int i=0;
                   while(tokenizer.hasMoreTokens())
                             array[i] = tokenizer.nextToken();
                             i++;
    Any suggestions welcome!
    thanks in advance!

    Hi
    sorry wrote in a hurry ;) din c the problem clearly
    there are two approaches
    1) best approach for your problem is Vector or ArrayList, these would make life easy for you.
    Always collections are better approach over arrays when the size is dynamic. However in your case the size cant be said to be DYNAMIC. coz the number of words will not grow / shrink during the runtime.. i know that number of words are not fixed but dynamic is something which will grow/shrink during runtime. but still collection is better approach.
    2)dirty approach
    use double dimensional array
    String arr[][] = null;
    then use one tokenizer for StringTokenizer(str,"\n");
    using countTokens on this will give you number of lines.
    use this to initialize array
    arr = new String[lineCount][];
    then iterate from 1 to lineCount and use 1 more tokenizer to get number of words for that line. use this number to initialize the column size for arr[i] like
    arr[i] = new String[wordCount];
    then store the token using nested for loops in this array
    go for the 1st one ;) 2nd one is hedious n time consuming but both will work ;)
    cheers
    amey

Maybe you are looking for

  • How to reformat a Macbook pro 2011 hard drive?

    Hello, How do you reformat a MacBook Pro (OS X 10.7.3) 2011s Hard drive? I already backed up all the files I wanted to save. But since I have the new Macbook pro 2011 (only a few months since I got it) it didn't come with an installation disc, but in

  • Error Code 10 with GPIB PCI Card

    PC used: Dell optiplex GX110, lastest Bios release, Windows 2000 SP4, GPIB Drivers version 2.2, Local Admin session. After having install the driver (without the GPIB)and plug the card, this one is automaticaly recognised by the Os. But, after the re

  • Sales Employee  VRTNR is missing in Field Catalog

    Hi, I can identify the field Sales employee  - VRTNR in Field Catalog(Pricing Sales/Distribution) but it is not availble to select when creating the condition  table. I can see other fields appearing but not the sales employee which  I can find in Co

  • Nokia E71- email client

    ive got a Nokia E71, and ive set up my Email client to my gmail account and whenever I reply to an email the text box area were you type your message in always appears with the Recipient message and i dont want there message so i have to delete it an

  • How to move stored procedure output to file

    Hi All, Thanks in advance. Please let me know how to move the oracle stored procedure output to the flat file. By Pyarajan