• Post Reply Bookmark Topic Watch Topic
  • New Topic

Adding amount fields in txt file  RSS feed

 
changu mani
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All,
I'm stuck. I need your help in resolving the below mentioned problem. The Requirement goes as follows :
I've a file which has the format shown below. The last field is amount. I need to read the file and get the last field in all rows and calculate the sum. The amount always comes between 5th and 6th Pipes.
5|10|||00781|5000|U;
2|10|||06381|4000|U;

This is my program



I've coded till I get the contents but I'm not able to find out the logic to get the last field between 5th and 6th pipes. Please help.

Thanks in Advance!
 
changu mani
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I rewrote the Process method.



Now I am able to get the fields. Thank you.
 
Rajdeep Biswas
Ranch Hand
Posts: 231
1
Eclipse IDE Java Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
changu mani wrote:Now I am able to get the fields. Thank you.


Have a look at java.util.StringTokenizer class that has relevant methods to do your task.
I will do the same with java.io.BufferedReader as recommended.

Read each line checking that its not null (null means that after last line, the read will return NULL)
|-- Break each line into tokens with pipe delimiter
|-- Find the sixth token as this has your data
|-- go to top --->>> read next line, and repeat process
 
Rajdeep Biswas
Ranch Hand
Posts: 231
1
Eclipse IDE Java Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!