954,545 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Extract Data from txt file using java

Hi Friends how to extract following data and store in string variable. All variable are string no need to use any other data type like datetime and so on.

Deposits and Additions
  Date      Description                                   Amount        Refe
  11/01     Test1 201f13050000100 NEWEDGE          1,500,000.00
            OBI:FFC SAN LAZARO, SA A/C 430
  11/01     Test2 20f113050021500 VIGO RE                149.00
            OBI:VIGO SETTLEMENT GTV14
  11/01     Deposit                                   350,777.06
  11/01     Opening Checking Deposit                   38,097.29
  11/02     Test3 20113060003600 GEORGE             350,000.00
            OBI:/RFB/TO ( MULTITRADING LIM
  11/02     Test4 20113060014100 1/SHARE            159,964.20
            OBI:/RFB/PAYMENT OF GOODS
  11/03     Test5 20113070029800 TJ HARK             52,660.00
            OBI:
  11/04     Test5 20113080002900 SHAREKA             80,000.00
            OBI:/RFB/TO (MULTITRADING LIMI
  11/04     Test6 20113080034100 ULTRA T             79,200.00
            OBI:PO : S/7960 INV : 6555 S/8
  11/04     Test7 20113080002800 GEORGE              60,000.00
            OBI:/RFB/TO ( MULTITRADING LIM
  11/04     Test8 20113080033400 BANCO I             22,826.00
            OBI:

After extract i get out like

Date : 11/01 
Description : Test1 20113050000100 NEWEDGE OBI:FFC SAN LAZARO, SA A/C 430
Amount : 1,500,000.00
Refe :

Date : 11/01 
Description : Test2 20113050021500 VIGO RE OBI:VIGO SETTLEMENT GTV14
Amount : 149.00
Refe :

Date : 11/01 
Description :Deposit
Amount : 350,777.06
Refe :

Date : 11/01 
Description :Opening Checking Deposit
Amount : 38,097.29
Refe :

Date : 11/01 
Description :Test3 20113060003600 GEORGE OBI:/RFB/TO ( MULTITRADING LIM
Amount : 350,000.00
Refe :


This is really urgent. Hoping sooner response from my friend z

Thanks in advance.

sunmania
Newbie Poster
1 post since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

The input data seems to be wrapped. Is that correct?
So there are really only 11 lines of data and two header lines?

thines01
Postaholic
Team Colleague
2,425 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402
 

If the data is in a file, you can use the Scanner class to read the contents of the file into Strings using one of its next....() methods.

NormR1
Posting Expert
Moderator
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656
 

Using the Scanner class would be the best. You can read each section of the file with it and specify the delimiter to use.

Something like this:

Scanner fileReader = new Scanner("FILENAME.txt");
while(fileReader.hasNext()) {
	String item = fileReader.next(" ");
	// Print or store the string, read in the next line
	System.out.println("First thing: " + item);
}
dmanw100
Posting Whiz in Training
242 posts since Apr 2008
Reputation Points: 104
Solved Threads: 27
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: