Search Through File with OPENCSV

All,
I am searching thru a .csv file for using regular expressions. I am looking for a patter that looks like a date: mm/dd/yyyy.
I search for the pattern while reading my .csv file. Since I am in a loop, I can't get a permanent handle on the search result. How can I get a permanent handle on it?
When I come out the loop, the date is empty or null.
How can I get the one occurrence, and save it?
Code:
package mybeans;
import org.apache.regexp.*;
import java.util.LinkedList;
import ClientDataProc.Logging;
import ClientDataProc.BalancesDataClass;
import ClientDataProc.ControlsAccess;
import au.com.bytecode.opencsv.CSVReader;
import java.util.List;
import java.io.*;
import java.io.FileReader;
import java.io.IOException;
public class CSVBalances {
static String find="";
//lets get headers from config file.
String[] headers;
String finalDate ="";
static String date ="";
private static Logging log = new Logging();
public static void main(String[] args) throws IOException {
          CSVBalances test = new CSVBalances();
          test.readData("Cash.csv", "royal.csv");
          System.out.println("From main" +date);
     public LinkedList<BalancesDataClass> readData(String filename, String config)throws IOException {
          ControlsAccess controls = new ControlsAccess(log);
          BalancesDataClass balances = new BalancesDataClass(controls, filename, -1,log);
          LinkedList<BalancesDataClass> list = new LinkedList<BalancesDataClass>();
          //lets get the date out of the file.
          CSVReader readerDate = new CSVReader(new FileReader(filename));
          String [] nextLineDate;
          while((nextLineDate = readerDate.readNext()) != null){
               for(int i = 0;i<nextLineDate.length;i++){
               finalDate = findDate(nextLineDate);
               if(finalDate != null || finalDate != ""){
                    date = finalDate;
                    System.out.println(date);
                    break;
               break;
               //now we read the data file.
               CSVReader reader = new CSVReader(new FileReader(filename),',','\"',3);
               String [] nextLine;
               //read the configuration file.
               File configFile = new File(config);
               CSVReader configReader = new CSVReader(new FileReader(configFile));
               while((headers = configReader.readNext()) != null){
                    //lets find the date in the file:
                    while ((nextLine = reader.readNext()) != null) {
                    for(int h =0; h<headers.length;h++){
                         System.out.println(headers[h] + nextLine[h]);
                         //add to our objects BalancesDataClass/ClientDataClass.
                         balances.saveData(headers[h], nextLine[h]);
               }return list;
     private static String findDate(String part){
          String date="";
          String pattern = "[0-9][0-9]" + "/" + "[0-9][0-9]" + "/" + "[0-9][0-9]";
          RE r = new RE(pattern);
          if(r.match(part)){
               //System.out.println("The match is: " + r.getParen(0));
               date = r.getParen(0);
          return date;
public String getDate(){
     return this.date;

Here is the snippet of my code. Can someone please take a look at it.
while ( (dbRecord = dis.readLine()) != null) {
StringTokenizer st = new StringTokenizer(dbRecord, ":", false);
Vector row = new Vector();
String lineTemp;
while (st.hasMoreTokens()) {
if (st.nextToken().trim().equalsIgnoreCase(userinput)) {
//System.out.println(dbRecord);
StringTokenizer tempst = new StringTokenizer(dbRecord, ":", false);
while (tempst.hasMoreTokens()){
row.addElement(tempst.nextToken());
dataVector.addElement(row);
}

Similar Messages

  • Read Document in FileUtilities  cannot search a file with french character in the file name

    Hi,
    I am trying to search a file with french character in the file name like 'captures écran.doc' in my unix server directory, and Write the file somewhere, say in a list of documents or, write on file system to another directory.
    I am using to Read Document in FileUtilities of Foundation, but it cannot read the file due to french character in its name. Although it can find any other file name without these french characters.
    Tried renaming but that also cannot find the file with french character name.
    Please provide any idea to solve it using LC operation.
    Regards,
    Rohan Raj.

    Hi Thomas,
    Thanks for the post, but I have already found a solution to it a month ago. Sorry for not posting the solution.
    You just have to set the '-Djava.property.file.encoding=ISO8859-1' into JVM argument of your server startup, and bounce the server back to pick the new JVM arg set. And now the service Read Document in FileUtilities of Foundation will read all french characters.
    ISO8859-1refers to "Latin alphabet no. 1," consisting of 191 characters from the Latin script. This character-encoding scheme is used throughout The Americas,Western Europe, Oceania, and much of Africa. It is also commonly used in most standard romanizations of East-Asian languages.
    regards,
    Rohan Raj.

  • How can I search for files with more than one keyword?

    I´ve created some keywords, and some files in my folder are tagged with two, three or more keywords.
    Is there a way to search for files using more than one keyword on the search field?
    Thanks!

    Use the Find command (menu Edit) and in criteria at the right side is a plus sign to add another criteria and set it to your custom wishes.
    make a choice in results and you should be OK

  • Spotlight content search : excludes files with .php5 extension

    My Spotlight does not find strings in files with .php5 extension. It probably does not consider these as text files.
    How can I change that ?

    I guess I found the right page :
    http://developer.apple.com/documentation/Carbon/Conceptual/understandingutis/understand_utis_intro/chapter_1_section_1.html#//appleref/doc/uid/TP40001319-CH201-SW1

  • How search a file with Forms 6i

    I want to know where is located a file system's file.
    Are there some libraries to include in Oracle Forms 6i?
    Thanks.

    thank you for your help, but it does not talk about how to search a file, and how to handle if the file does not exist, and needs to create it.

  • Search text file with 2 string tokens

    I am reading a text file which contains database records. I am able to search with lastname(the user enters it in the textfield using GUI frontend). this search useus stringtokenizers. take the users input and search all the tokens and see which token matches the key and prints that record. Can someone please give me some advice to do a search using both last name and first name at the same time. In this case i will have to do a seach using 2 tokens which i dont know how to do. thanks.

    Here is the snippet of my code. Can someone please take a look at it.
    while ( (dbRecord = dis.readLine()) != null) {
    StringTokenizer st = new StringTokenizer(dbRecord, ":", false);
    Vector row = new Vector();
    String lineTemp;
    while (st.hasMoreTokens()) {
    if (st.nextToken().trim().equalsIgnoreCase(userinput)) {
    //System.out.println(dbRecord);
    StringTokenizer tempst = new StringTokenizer(dbRecord, ":", false);
    while (tempst.hasMoreTokens()){
    row.addElement(tempst.nextToken());
    dataVector.addElement(row);
    }

  • Search a file with JComboBox

    Can anyone help me, i'm doing a sistem where there will be a JComboBox and when i choose the value which is a folder name in the combo it have to search the in the folder look for a file for example oratab. if the file in not found in the folder a message have to display file not found. once the file is found the content in the file have to display in a JListBox. CAN ANYONE HELP ME... I'M RUNNING OUT OF TIME...

    What's wrong with using a JFileChooser, which is actually designed for selecting files?

  • Search through files in a directory

    How do I get a list of the files in a directory? I am aware of JFileChooser but it is not what I am looking. I need to search the contents of the xml files in the directory. I can do this with one file but need to do it with them all.

    // where files in subdirectory \files below the application directory
    File dir = new File(".\\files\\");
      if(dir.exists()){
        File[] list = dir.listFiles();
        for (int i = 0; i < list.length; i++){
          String fileName = list.toString();
    int iPtr = fileName.lastIndexOf("\\");
    int jPtr = fileName.indexOf(".xml",0);
    if (jPtr>-1) {
    String longName = fileName;
    String shortName = fileName.substring(iPtr + 1, jPtr);
    // file name in short name

  • Looping through files with Regular expressions ?

    Hi,
    My Question is:
    if i have the following Regular Expression,
    String regrex = "tree\\s\\w{1,4}.+\\s=\\s(.*;)";
    The file in which i am looking for the string has multiple entries, is it
    possible to do another regular expression on the captured group (.*;)
    which is in the original Regular expression ?
    The text that is captured by the RE is of the type "(1,(2,((3,5),4)));" for
    each entry, and different entries in the file have slightly different syntax
    is it possible to loop through the file and first of all check for the presence
    of the original RE in each entry of the file
    and then secondly, check for the presence of another RE on the captured group?
    [ e.g. to check for something like, if the captured group has a 1 followed by a 3
    followed by a 5 followed by a and so on ].
    Thanks Very much for any help, i've been struggling with this for a while!!
    Much appreciated
    The code that i have so far is as follows:
    import java.util.*;
    import java.util.regex.*;
    import java.io.*;
    import java.lang.*;
    import javax.swing.*;
    public class ExpressReg {
    public String Edit;
    public ExpressReg(String editorEx){
    Edit = editorEx; // Edit = JTextArea
    String regrex = "tree\\s\\w{1,4}.+\\s=\\s(.*;)";
    //String regrex1 = "(.*;)";
    Pattern p = Pattern.compile(regrex);
    Matcher m = p.matcher(editorEx); // matcher can have more than one argument!
    boolean result = m.find();
    if(result){                           
    JOptionPane.showMessageDialog(null, "String Present in Editor");
    else if(!result){
    JOptionPane.showMessageDialog(null, "String Not Present In Editor");

    if i have the following Regular Expression,
    String regrex = "tree\\s\\w{1,4}.+\\s=\\s(.*;)";
    The file in which i am looking for the string has multiple entries, is it
    possible to do another regular expression on the captured group (.*;)
    which is in the original Regular expression ?Yes, the capturing group is $1 (the only one) referenced in source code as m.group(1).
    m.group() will return entire matching.
    simply use this way:
    String result = m.group(1);
    // your stuff: could be another validation
    The text that is captured by the RE is of the type "(1,(2,((3,5),4)));" for
    each entry, and different entries in the file have slightly different syntax
    is it possible to loop through the file and first of all check for the presence
    of the original RE in each entry of the file
    and then secondly, check for the presence of another RE on the captured group?Again "Yes", no limits!
    Don't need to create another Matcher, just use m.reset(anotherSourceString)..loop using the same pattern.
    Note: Take care with ".*" because regex nature is "greedy", be more specific, eg.: "\\d" just matches digits (0-9).
    Can you give us some sample of "slight difference" ?

  • Search pdf files with Windows Desktop Search

    I recently installed Windows 7 and have attemped to use Windows Desktop Search to search for text contained in pdf files without success.  Today I found a reference to Adobe PDF IFilter v6.0 at http://www.adobe.com/support/downloads/detail.jsp?ftpID=2611.  I have Acrobat 8.2.1 installed on my computer.  Since I couldn't figure out if the iFilter had already been installed, I downloaded the ifilter60.exe file.  However, when I ran this exe file I didn't see any evidence that the filter was installed.  For example, the above web page mentions a ReadMe file file which is "included with the download" but I don't know where it or the plugin can be found.  I'm still unable to search within pdf files.  Is there anything special I need to do to install this IFilter?
    Peter

    Can't help directly on the question. However, the generic problem in Windows is that the search will only delve into a list of MS denoted file types. I spent a year looking for a file I had misplaced and did not remember the name of. The following link resolved my issue and now I can search for anything in any file. I followed the registry edit in the response. Editing the registry can be dangerous and you should back up the registry at a minimum unless you know what you are doing. I also do not know if the fix is available in Windows 7. As I recall, I did find it in VISTA. Good luck if you use this, but also be careful. Bill
    http://www.winvistatips.com/search-inside-bas-and-frm-files-t570174.html

  • Searching for pictures with 2 keywords

    Hi guys, I was just wondering if there is way to search for files with two specific keywords.
    Lets say that I want to find picture that contains both Nicol and Brandy keywords. Not just one or the other. Is there any way to that in Bridge CS5?
       Thanks for your help.  Charles

    Yes, yes there is.  You need to use the Find function (Ctrl F in Windows).
    With the Find window you will see a + at the right edge of Criteria line.  Click that and it will add lines.
    Select the Match for "All criteria met".

  • Looking for a free iOS 4 app that can search through .pdf files or spreadsheets

    Looking for a free iOS 4 app that can search through .pdf files or spreadsheet    
    Thanks

    Hey there
    "pdf creator" for iPad works flawlessly for me working with pdf files
    It takes care of all my needs
    I'm not sure about sending via Wifi or Bluetooth but I send them via e- mail all the time
    Possibly it could handle your needs as well
    Just type it into the App Store search field and the first one that comes up is the one I use
    Jump on over there and read up on it before buying and see if it will help you 
    Hope this helps
    Regards

  • Searching through .fla files

    Usually when I am looking for a specific field name, section of code or variable, I will run a GREP regex search to search through my ASP files, which works great as they are just stored as plain text, however I was wondering if anyone knows of a way to do the same with ".fla" files.
    The GREP search looks through all my files in one go and returns a list of files which match the search terms; but wouldn't work on .fla files as the actionscript is not stored as plain text. Possibly this would work if I converted all my ".fla"s to use seperate ".as" files but this would be a lot of work and I'd rather avoid it if possible.
    Thanks for any help you can give.

    Select the stage window, then select Search and Replace from the Edit menu. This search tool works pretty well. If you search when an Actionscript window is selected you will only be able to search that one frame of AS.

  • Sorry, something went wrong - Open Office File from Search Results Page with Office Web Apps

    Hi,
    I'm getting "Sorry, something went wrong" error when I'm trying to open any office document from inside Search Results Page with Office Web Apps, the same error is appearing in the document preview as well.
    The error in SharePoint logs says that the file cannot be found.
    Please note that this error is coming only when the "Filename" of the document is not written in English (in my case its written with Arabic characters).
    If I try to open it from the document library, its opening properly with no errors.
    The only difference between two URLs (document URL in Search Results and in Document Library) is the value for "sourcedoc" attribute;
    In the case of Search Results page, the filename in "sourcedoc" attribute is kept as is with Arabic characters.
    While in the Document Library, the filename in "sourcedoc" attribute is converted into different characters (something like: "B9%D9%85%D9%8").
    Anybody have an idea on how to overcome this issue, implement a workaround or modify the "sourcedoc" behavior?
    Thanks in Advance.
    Hamza AlSughier

    Dear Wendy,
    Thanks for your efforts, I already tried your last suggestion before, but this didn't solve my problem.
    Actually my end users are accessing this portal using ADFS and HTTPS.
    Finally I got this solved, I have done below to get my overall solution working perfectly:
    - First I have configured Windows Authentication and ADFS Authentication on the same zone which is the default zone.
    - The issue when opening office documents with Arabic file name has disappeared as a result of first change.
    - Then I have faced an issue where we are not able to crawl content under Default zone, however we have to do so, after too many efforts, I found that its related to the Load-balancer/proxy, I have made the crawler server
    to crawl himself (http://CrawlServerName:PortNumber).
    - Also a change on Alternate Access Mapping was needed, I have set one of the extended zones (which is running Windows Authentication only) as Internal URL for the Default Zone, and this is was the URL I used for Crawling.
    I have configured Server Name Mappings to make sure we got proper URLs in Search Results.
    - Then we faced another issue, which is Authentication selection on login page (How to bypass this page, and authenticate using ADFS auto), I used this solution (Set Custom Sign In Page):
    http://0ut0ftheb0x.wordpress.com/2014/01/04/skip-the-authentication-selection-page-at-_logindefault-aspx-in-a-mixed-authentication-environment/.
    - I faced one more issue as a result of above workaround; Sign Out functionality wasn't working well; users get logged in automatically whenever I click on Sign Out. I solved this by modifying the "Sign Out" Control under _layouts;
    I made it to redirect users to ADFS Sign Out Page instead of SharePoint Sign Out Page (I know its not recommended, but I don't have any other option).
    Hamza AlSughier

  • I am running Mac OSx Lion 10.7.2. My problem is I can't search on an external network server for a file with the finder toolbar anymore. Nothing shows up and it will not search. I was able to in snow-leopard and am no longer able to w. Lion. Suggestions?

    I am running Mac OSx Lion 10.7.2.
    My issue is that I am not able to run a search in the finder toolabar on a network server. No files show up nor does it search on the server anymore. I was able to run the search in snow-leopard and am no longer able to do so with Lion. Is there a preference I can change or some kind of app or program I can download that will help me with this issue? This is extremely problematic for me as I am searching for files all day everyday. Thank you!

    Hello,
    It isn't the fw in Network you want o use or look at, that's for something completely different.
    My first suspect is the Power Adapter on the LaCie has gone.
    At the Apple Icon at top left>About this Mac, then click on More Info, then click on Hardware>Firewire, what is listed there?
    Reset the Firewire bus
    If your Firewire or USB isn't recognizing any device.  A solution which has worked for some whose hard drive became invisible in 10.4 was simply to follow these four steps to reset the Firewire/USB bus:
    1. Shut the machine down.
    2. UNPLUG the power lead to the computer and any firewire/USB drive or devices.
    3. leave it for 10 minutes.
    4. Connect back up and reboot.
    http://www.macmaps.com/firewirebug2.html

Maybe you are looking for

  • How to Set Up the Wireless Rounter

    Yesterday I bought a wireless rounter. It's from Linksys. The model no. is "WRT54G". After I set it up, the Internet worked just fine, but I couldn't log on the Microsoft messenger at all. What should I do? This frustated me a lot. I don't know where

  • I get an error when starting firefox on several user profiles: the bookmarks and history are not functional something about the file being in use.

    Windows Server 2008 R2, Windows 7 workstations, the appdata folder is redirected to a network share at \\server\profiles and several users are unable to use bookmarks getting an error about the file being in use. I'm wondering if maybe my antivirus (

  • Skype number not working

    Evening to all. Purchased skype number yesterday, have gone through what I think is all of the replies, and tried them all, my skype number is still always busy..........please help. Thankyou

  • Why SSH is secured over telnet

    Why SSH is secured over telnet? Hi folks, Why telnet is not secured and why SSh is secured? Regards Thanveer "Everybody is genius. But if you judge a fish by its ability to climb a tree, it will live its whole life believing that it is a stupid."    

  • Sent multiple page Word document containing photos

    I had a 22-page Word document containing a table with small photos of dvds on my old Dell Inspiron laptop.  I forwarded this Word document to my Apple iMac Desktop as an attachment.  When I opened document it only shows page 1 and not the remaining p