• 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

readLine() Deprecated

 
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there no other way to read what the
DataOutputStream() created except by DataInputStream()?
My problem is how to read what
DataOutputStream.writeChars()
had made.
If I used readLine() of DataInputStream its deprecated...
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can use readLine method of BufferedReader class for reading from the DataInputStream
Wrap the DataInputStream in the BufferedReader object by using this code
BufferedReader d = new BufferedReader(new InputStreamReader(in));
where 'in' is the object of DataInputStream.
 
Nelson Nadal
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is the code...


I changed to this...


Still it's not showing the right thing...
 
Veena Rani
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you have created your file using DataOutStream writeInt, writeDouble etc. then only you can read it using readInt() or readDouble() etc.
If you have a simple text file then you can not use readInt or readDouble.
In case of normal text file with tab seperated data you can use BufferReader to read the line by line record and seperate the tab seperated data using StringTokenizer.
Your code will look something like this
while ((desc = brin.readLine()) != null) {
StringTokenizer st = new StringTokenizer(desc,"\t");
//some check for no. of tokens
unit = Integer.parseInt(st.nextToken());
price = Integer.parseInt(st.nextToken());
desc = st.nextToken();
System.out.println("You've ordered " +unit + " units of " +desc + " at $" + price);
System.out.println(desc);
total = total + unit * price;
}
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic