• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Print Stream problem

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,
i have some question regrading chracter Stream.
1- when we write data through "PrintStream class" and read through "BufferInputStream class" method readLine().
It is recmonded that the sequence in which u write the data, You must be read in that order. Otherwise u get FormateException.
What is the reason of such sequence of reading data . Even casting is not helpfull ??
2 - "PrintStream class" write data into file. It write into file Least Significant bits or Most Significant bits???
The sample code is more accurate for u ..
PrintWriter pw = new PrintWriter( new OutputStreamWriter ( new FileOutputStream ("aatif.txt"), "UTF8" ) ,true ) ;

pw.println('A') ;
pw.println('B') ;

pw.close();
FileInputStream fi = new FileInputStream ("aatif.txt");

int a1 =0;
while ( ( a1 = fi.read() ) != -1 ){
System.out.println(a1);
}
This code generates the out put is
65
13
10
66
13
10
The 65, 66 is ASCII code (A, B) but what about 13 , 10 .
If i write int type data then out is also very confusing me , That what is the writing and reading process of stream .???
As I am comfortable with ByteStram .
Please Help me .
Thanks in Advance
:roll:
 
Chicken Farmer ()
Posts: 1932
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
13 is a carriage return, 10 is a newline feed.
See the ASCII table for all the codes, it's quite helpful.
 
Nawab Ahmed Siddiqui
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks adams
but one point is remainig that

what is the reason taht when we write data via PrintStream class , then i should be read the data in the same order why ???
i.e if u write 1st int , 2nd is double .Then u should be read data by BufferdInputStream class Method readLine() must in the same order .
when i write numeric data then read it the out put is unpredictable for me.
i donot know still now that where printStream write (least significant, or most significant bits).
i am thanks full to u a lot !!!
 
jason adam
Chicken Farmer ()
Posts: 1932
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As far as ordering, that's the way streams go. It's first in, first out, at least with all my experiences. For instance, if you write two ints to a stream, and then want to get one of them out, if the ints didn't leave the stream in the same order, how would the stream know what int you wanted? It's very predictable output when it comes to order.
Not sure I understand your second question. Perhaps you are using the wrong class? Do you want to deal with characters? If so, use a FileReader, not a FileInputStream. The general rule is if you are dealing with characters, do Readers. If you want bytes, do streams.
That being said, perhaps you can give a more elaborate example of the problem you are having with your second concern?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic