5 Replies Latest reply: Apr 14, 2009 5:57 AM by 807588 RSS

    reading text file value

    807588
      Dear all
      i have a text file in which we have column aname and there values which are pipe(|)seprated as below
      Message Identifier|Processing Code|Transaction Amount|Transmission Date & Time (DDMMYYYYHHMMSS)|Systems Trace Audit Number|Capture Date(MMDD)|Point of Serivce entry mode|Point of Service Condition Code|Retrieval Reference Number|Card Acceptor Terminal Identification|Primary Account Number|Settlement Date (MMDD)|Authorization Identification Response|Response Code|Retailer’s ID
      0210|000030|000000000600|31032009130109|147258|0331|010|59|996735027800|70000107|1723456789|0104|147852|aa|mydemocompany

      i need to insert these value in mysql database using jsp code
      i have create database in which i have taken all the value as varchar except date
      please help me ASAP

      Edited by: arun240 on Apr 14, 2009 9:23 AM
        • 1. Re: reading text file value
          807588
          Hi arun240,

          You've just to read your text file with a BufferedReader and for each line, you use a Pattern to extract the values.
          Example =
              Pattern pat = Pattern.compile("\\|");
              String line = "0210|000030|000000000600|31032009130109|147258|0331|010|59|996735027800|70000107|1723456789|0104|147852|aa|mydemocompany";
              String[] result = pat.split(line);
              for (String s : result) {
                  System.out.println(s);
              }
          Edited by: Chicon on Apr 14, 2009 9:47 AM
          • 2. Re: reading text file value
            807588
            hi chicon
            my will be change dail so the value like mesage identifier 00211 will change on daily bases
            so i can not hard coded it
            • 3. Re: reading text file value
              807588
              hi chicon
              my will be change dail so the value like mesage identifier 00211 will change on daily bases
              so i can not hard coded it
              • 4. Re: reading text file value
                807588
                You don't have to hard code it ! I just used your sample to show you how to extract values from a string using the Pattern class.
                You may do something like this :
                private void parseFile() throws Exception {
                    Pattern pat = Pattern.compile("\\|");
                    String line;
                    BufferedReader reader = new BufferedReader(new FileReader("file.txt"));
                    line = reader.readLine();
                    while (line != null) {
                       retrieveValues(pat.split(line));
                       line = reader.readLine();
                    }
                    reader.close();
                }
                
                private void retrieveValues(String[] values) {
                    // TODO
                }
                • 5. Re: reading text file value
                  807588
                  hi,
                  thanks for helpful update
                  now my problem is that how i can take the value after reatiler id
                  as i do not need column name i need only valueshow i can store the value from text file .