This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes I/O and Streams and the fly likes Reading a text file and then generate other output Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Reading a text file and then generate other output" Watch "Reading a text file and then generate other output" New topic
Author

Reading a text file and then generate other output

kirankkmm kumar
Greenhorn

Joined: Sep 17, 2010
Posts: 7


Need to read a text file and then generate new out put with values should be changed.


Below is the text file ...//abc.txt

dn: uid=br4805, ou=People, dc=access,dc=ai,dc=com
givenName: Carl
sn: Getman
userPassword:: e1NIQ
aigrole:ker
physicalDeliveryOfficeName: Hastings-Tapley .
l: Woburn


//expected output

dn: uid=, ou=, dc=bb,dc=bb dc=computer
givenName: Carlaxmoya
sn: moya
userPassword::
aigrole:
DeliveryOfficeName: Hastings-Tapley .
l: Woburn


please help me out how to resolve this issue.please do the needful .

thanks in advance
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
Is the problem in reading/writing text files, or in altering the contents of the lines in between? If the former, check out the java.io.File, FileReader and BufferedReader classes. If the latter, then the java.lang.String class and its indexOf and substring methods will be helpful.
kirankkmm kumar
Greenhorn

Joined: Sep 17, 2010
Posts: 7
I tried using the below code ,but i need to store every record in the Hashmap .please go through the below code



I need to store a a number of records in hashmap by reading it from text file.

below is the code .






//testall.ldif


dn: uid=br152, ou=People, dc=acceg,dc=ag,dc=com
displayName: br152
homePhone: 87878
givenName: Nickkk
aigrole: SWC_Brokery
mobile: 888667575

dn: uid=br152g, ou=People, dc=acce,dc=ng,dc=com
displayName: br152g
homePhone: 56565
givenName: Nickfsfsf
aigrole: SWoker
mobile: 343434675


dn: uid=br1, ou=People, dc=achg,dc=aig,dc=com
displayName: br1
homePhone:
givenName: dfdf
aigrole: dfser
mobile: 6575755756



The output should be as below





Please do the needful ,help me to resolve this issue.


thanks in advance

Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
At a quick glance, the output looks just like the input, except for the "Record 1:", "Record 2:" etc. lines. Are you asking how to add those lines?
kirankkmm kumar
Greenhorn

Joined: Sep 17, 2010
Posts: 7
yeah exactly i need to store each record as i mentioned above.....


try to solve me the issues.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10268
    
    8

kirankkmm kumar wrote:


Please check your private messages for an important administrative matter.

[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
It seems that adding something like

if (record.indexOf("dn:") > -1)
System.out.println("Record "+recCount+":")


before "System.out.println(record)" should do the trick.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Reading a text file and then generate other output