stream question ?

N

news.t-com.hr

File file = new File("c:\\test.txt");
InputStream inputFileStream = null;
//0inputFileStream = new BufferedInputStream(new FileInputStream(file));
BufferedReader r = null;
Reader fReader = null;
System.out.println(inputFileStream);
fReader = new InputStreamReader(inputFileStream,"ISO-8859-1");
r = new BufferedReader(fReader);
while (r.ready()) {
String line = r.readLine();
}
//1
inputFileStream = new BufferedInputStream(new FileInputStream(file));
//2

My question is why is it if I call inputFileStream.available() on comment 1
, I get zero , and when i call it on line two it is not zero ? , and
on comment 2 , do I have two stream's open, or just one, because before
calling inputFileStream = new BufferedInputStream(new
FileInputStream(file));
i didn't closed inputFileStream opened on comment 0?

Thanks in advance.
 
R

Roedy Green

File file = new File("c:\\test.txt");
InputStream inputFileStream = null;
//0inputFileStream = new BufferedInputStream(new FileInputStream(file));
BufferedReader r = null;
Reader fReader = null;
System.out.println(inputFileStream);
fReader = new InputStreamReader(inputFileStream,"ISO-8859-1");
r = new BufferedReader(fReader);
while (r.ready()) {
String line = r.readLine();
}
//1
inputFileStream = new BufferedInputStream(new FileInputStream(file));
//2

My question is why is it if I call inputFileStream.available() on comment 1
, I get zero , and when i call it on line two it is not zero ? , and
on comment 2 , do I have two stream's open, or just one, because before
calling inputFileStream = new BufferedInputStream(new
FileInputStream(file));

Do did not your precise code, so I am only guessing what you really
wrote.

I suspect all that is happening is BufferedInputStream has to keep a
buffer full ahead, though I don't believe it uses any non-blocking I/O
to effect that the way we did back in the 60s.


--
Roedy Green Canadian Mind Products
http://mindprod.com

"Any one who considers arithmetical methods of producing random digits is, of course, in a state of sin. For, as has been pointed out several times, there is no such thing as a random number — there are only methods to produce random numbers, and a strict arithmetic procedure of course is not such a method."
~ John von Neumann (born: 1903-12-28 died: 1957-02-08 at age: 53)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top