• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Reading a text file and then generate other output

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
 
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1337
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yeah exactly i need to store each record as i mentioned above.....


try to solve me the issues.
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

kirankkmm kumar wrote:



Please check your private messages for an important administrative matter.
 
Lester Burnham
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic