• 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
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

Buffered Readers and hashtables.

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

import java.io.*;
import java.util.*;
public class SS7Office
{
public static void main(String args[]) {
try {
final int TT_NUMBER=12; ;
BufferedReader br=new BufferedReader(new FileReader("ss7.con"));
Hashtable ht=new Hashtable();
String s=br.readLine();
while( s !=null ) {
StringTokenizer st=new StringTokenizer(s,"^");
String token = st.nextToken();
if(!token.equals("12")){
//System.out.println(" TOKEN IS "+token);
System.out.println(s);
} else{
System.out.println(" TOKEN IS FOUND WITH 12");
for( int index=0; st.hasMoreTokens(); index++) {
ht.put( new Integer(index +1), st.nextToken());
}
ht.put(new Integer(39),new Integer(15));
ht.put(new Integer(43),new Integer(60));
ht.put(new Integer(45),new Integer(30));
ht.put(new Integer(47),new Integer(30));
ht.put(new Integer(49),new Integer(15));
ht.put(new Integer(51),new Integer(240));
ht.put(new Integer(21),new Integer(15));
ht.put(new Integer(23),new Integer(60));
ht.put(new Integer(25),new Integer(15));
ht.put(new Integer(27),new Integer(60));
ht.put(new Integer(29),new Integer(15));
ht.put(new Integer(31),new Integer(60));
ht.put(new Integer(33),new Integer(10));
ht.put(new Integer(53),new Integer(480));
ht.put(new Integer(55),new Integer(15));
ht.put(new Integer(71),new Integer(4));
ht.put(new Integer(67),new Integer(20));
ht.put(new Integer(65),new Integer(4));
ht.put(new Integer(35),new Integer(5));
ht.put(new Integer(37),new Integer(5));

System.out.println(" REPLACED VALUE IN HASH "+ht);
}
s=br.readLine();
}
br.close();
}catch(Exception e){
System.out.println(" Exception e"+e.toString());
e.printStackTrace();
}
}
}
My input file is ss7.con which i have to read till the 12th line,if it is not the 12th line ,I have to write it out to the screen,when I reach the 12th line I have to replace the values in the 12th line by those I have put in the hashtable.
The program does the above,but when it reaches the 12th line I have put the values to hashtable,but HOW do I write it to the file and display it on the screen.The final output on the screen must have all the llines in the i/p file includung the 12th line with the new replaced values.
Kindly help me.Thanks.
 
"Don't believe every tiny ad you see on the internet. But this one is rock solid." - George Washington
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic