File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reading a text file and then generate other output

 
kirankkmm kumar
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Lester Burnham
Rancher
Posts: 1337
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah exactly i need to store each record as i mentioned above.....


try to solve me the issues.
 
Maneesh Godbole
Saloon Keeper
Posts: 10971
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
kirankkmm kumar wrote:


Please check your private messages for an important administrative matter.
 
Lester Burnham
Rancher
Posts: 1337
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic