BufferedReader amount of bytes read
Per my knowledge the buffered reader is way optimized than non buffered as each read will be done from memory , no need for I/O read/write from disk/network each time.
So I was reading the answers here :
Specific difference between bufferedreader and filereader
I got confused by the second answer which seems to have high votes :
When the "read" instruction is given to the BufferedReader object, it uses the FileReader object to read the data from the file. When an instruction is given, the FileReader object reads 2 (or 4) bytes at a time and returns the data to the BufferedReader and the reader keeps doing that until it hits 'n' or 'rn' (The end of the line symbol). Once a line is buffered, the reader waits patiently, until the instruction to buffer the next line is given.
is that correct ? I would think we lost the whole idea about buffer reader, if the buffer need to do multiple 2 bytes read then I can just use the file reader and can use that too. The idea in buffered reader it should read large block at a time so the number of I/O access will be much less than file reader.
can anyone correct me if I'm wrong ?
java
add a comment |
Per my knowledge the buffered reader is way optimized than non buffered as each read will be done from memory , no need for I/O read/write from disk/network each time.
So I was reading the answers here :
Specific difference between bufferedreader and filereader
I got confused by the second answer which seems to have high votes :
When the "read" instruction is given to the BufferedReader object, it uses the FileReader object to read the data from the file. When an instruction is given, the FileReader object reads 2 (or 4) bytes at a time and returns the data to the BufferedReader and the reader keeps doing that until it hits 'n' or 'rn' (The end of the line symbol). Once a line is buffered, the reader waits patiently, until the instruction to buffer the next line is given.
is that correct ? I would think we lost the whole idea about buffer reader, if the buffer need to do multiple 2 bytes read then I can just use the file reader and can use that too. The idea in buffered reader it should read large block at a time so the number of I/O access will be much less than file reader.
can anyone correct me if I'm wrong ?
java
1
That does not sound correct. A file (on disc) is typically read a sector at a time (usually around 4k) and OSs typically buffer ahead and read more. So 2 or 4 bytes at a time sounds way off.
– markspace
Dec 31 '18 at 9:34
@markspace so shouldn't the buffered reader read one large block ?
– Mohammad Karmi
Dec 31 '18 at 9:36
Despite the many upvotes of that answer, this is clearly wrong.
– Henry
Dec 31 '18 at 9:36
2
The OS uses its own buffers. The only advantage to a Java buffer would be, I think, to reduce the number of OS calls to read data, but that's between the OS and Java, not the file itself.
– markspace
Dec 31 '18 at 9:37
add a comment |
Per my knowledge the buffered reader is way optimized than non buffered as each read will be done from memory , no need for I/O read/write from disk/network each time.
So I was reading the answers here :
Specific difference between bufferedreader and filereader
I got confused by the second answer which seems to have high votes :
When the "read" instruction is given to the BufferedReader object, it uses the FileReader object to read the data from the file. When an instruction is given, the FileReader object reads 2 (or 4) bytes at a time and returns the data to the BufferedReader and the reader keeps doing that until it hits 'n' or 'rn' (The end of the line symbol). Once a line is buffered, the reader waits patiently, until the instruction to buffer the next line is given.
is that correct ? I would think we lost the whole idea about buffer reader, if the buffer need to do multiple 2 bytes read then I can just use the file reader and can use that too. The idea in buffered reader it should read large block at a time so the number of I/O access will be much less than file reader.
can anyone correct me if I'm wrong ?
java
Per my knowledge the buffered reader is way optimized than non buffered as each read will be done from memory , no need for I/O read/write from disk/network each time.
So I was reading the answers here :
Specific difference between bufferedreader and filereader
I got confused by the second answer which seems to have high votes :
When the "read" instruction is given to the BufferedReader object, it uses the FileReader object to read the data from the file. When an instruction is given, the FileReader object reads 2 (or 4) bytes at a time and returns the data to the BufferedReader and the reader keeps doing that until it hits 'n' or 'rn' (The end of the line symbol). Once a line is buffered, the reader waits patiently, until the instruction to buffer the next line is given.
is that correct ? I would think we lost the whole idea about buffer reader, if the buffer need to do multiple 2 bytes read then I can just use the file reader and can use that too. The idea in buffered reader it should read large block at a time so the number of I/O access will be much less than file reader.
can anyone correct me if I'm wrong ?
java
java
asked Dec 31 '18 at 9:30
Mohammad KarmiMohammad Karmi
4401517
4401517
1
That does not sound correct. A file (on disc) is typically read a sector at a time (usually around 4k) and OSs typically buffer ahead and read more. So 2 or 4 bytes at a time sounds way off.
– markspace
Dec 31 '18 at 9:34
@markspace so shouldn't the buffered reader read one large block ?
– Mohammad Karmi
Dec 31 '18 at 9:36
Despite the many upvotes of that answer, this is clearly wrong.
– Henry
Dec 31 '18 at 9:36
2
The OS uses its own buffers. The only advantage to a Java buffer would be, I think, to reduce the number of OS calls to read data, but that's between the OS and Java, not the file itself.
– markspace
Dec 31 '18 at 9:37
add a comment |
1
That does not sound correct. A file (on disc) is typically read a sector at a time (usually around 4k) and OSs typically buffer ahead and read more. So 2 or 4 bytes at a time sounds way off.
– markspace
Dec 31 '18 at 9:34
@markspace so shouldn't the buffered reader read one large block ?
– Mohammad Karmi
Dec 31 '18 at 9:36
Despite the many upvotes of that answer, this is clearly wrong.
– Henry
Dec 31 '18 at 9:36
2
The OS uses its own buffers. The only advantage to a Java buffer would be, I think, to reduce the number of OS calls to read data, but that's between the OS and Java, not the file itself.
– markspace
Dec 31 '18 at 9:37
1
1
That does not sound correct. A file (on disc) is typically read a sector at a time (usually around 4k) and OSs typically buffer ahead and read more. So 2 or 4 bytes at a time sounds way off.
– markspace
Dec 31 '18 at 9:34
That does not sound correct. A file (on disc) is typically read a sector at a time (usually around 4k) and OSs typically buffer ahead and read more. So 2 or 4 bytes at a time sounds way off.
– markspace
Dec 31 '18 at 9:34
@markspace so shouldn't the buffered reader read one large block ?
– Mohammad Karmi
Dec 31 '18 at 9:36
@markspace so shouldn't the buffered reader read one large block ?
– Mohammad Karmi
Dec 31 '18 at 9:36
Despite the many upvotes of that answer, this is clearly wrong.
– Henry
Dec 31 '18 at 9:36
Despite the many upvotes of that answer, this is clearly wrong.
– Henry
Dec 31 '18 at 9:36
2
2
The OS uses its own buffers. The only advantage to a Java buffer would be, I think, to reduce the number of OS calls to read data, but that's between the OS and Java, not the file itself.
– markspace
Dec 31 '18 at 9:37
The OS uses its own buffers. The only advantage to a Java buffer would be, I think, to reduce the number of OS calls to read data, but that's between the OS and Java, not the file itself.
– markspace
Dec 31 '18 at 9:37
add a comment |
2 Answers
2
active
oldest
votes
Take a look at BufferedReader javadoc:
Reads text from a character-input stream, buffering characters so as to provide for the efficient reading of characters, arrays, and lines.
The buffer size may be specified, or the default size may be used. The default is large enough for most purposes.
In general, each read request made of a Reader causes a corresponding read request to be made of the underlying character or byte stream. It is therefore advisable to wrap a BufferedReader around any Reader whose read() operations may be costly, such as FileReaders and InputStreamReaders. For example,
BufferedReader in
= new BufferedReader(new FileReader("foo.in"));
will buffer the input from the specified file. Without buffering, each invocation of read() or readLine() could cause bytes to be read from the file, converted into characters, and then returned, which can be very inefficient.
Programs that use DataInputStreams for textual input can be localized by replacing each DataInputStream with an appropriate BufferedReader.
So it buffers the data beforehand from the underlying resource and consequent read instructions use the buffer for efficiency.
Yes it buffers the input but we arguing on the amount stored at a time , just to make it clear with the question. the buffering will be done on large block not 2bytes at time.
– Mohammad Karmi
Dec 31 '18 at 9:56
Read the second line again: It's size could be default which suits most apps or it can be specified.
– Masked Man
Dec 31 '18 at 10:44
add a comment |
The point he's making is that FileInputStream reads N bytes at a time and takes no interest in the data it reads. BufferedReader eventually uses FileInputStream (when reading a file) and does the repetitive read part but it does take an interest in the bytes it reads, treating them as character data (encoding considerations etc) chopping them up into lines
Sure, you can write your own, and not use BufferedReader, but you can say the same about anything in computing: "I didn't like NVidia's display driver, so I sat down and spent 3 years writing my own. Now I'm starting a new operating system. Be done for when quantum computers are mainstream" - nearly no-one does this; it's called reinventing the wheel and there's a reason why we don't do it: for the most part, the wheels other people invented are already fine for our purposes/better than we have time to do ourselves
Note; you seem to be taking issue with the assertion that BufferedReader ultimately reads from the data source a byte or two at a time. It probably doesn't, but I don't think that's the point the guy is making (the language used in the post is rather vague). Regardless of how it reads bytes from an InputStream/Reader, a BufferedReader will certainly inspect the data that it reads on a character-by-character basis as it looks for newlines, so it can make ReadLine() work. It will do this independently of the strategy that it uses to read the file (maybe it repeatedly reads in 4096 byte chunks, but it will certainly have to process the data byte by byte as it interprets it)
Ultimately consider that file access is cached and coalescing of reads may occur at many levels: calling ReaderX.Read() will almost certainly not cause a hard disk to stop everything it's doing, go to a certain sector, read a single byte, and go back to what it was doing before. You might thus issue a million calls to Read() one char that cause no more hard disk thrashing than a single call to Read() into a megabyte buffer
1
you are saying that bufferedreader does repetitive part of reading bytes ? I don't think so, the idea of buffered reader to reduce the access to disk which will read one large block at a time.
– Mohammad Karmi
Dec 31 '18 at 9:45
Edited to add a comment on this
– Caius Jard
Dec 31 '18 at 9:46
ok got it , that what I was looking for :) , I know that the 16 bit need to be interpreted to a valid character but ofcourse not reading 16bit each time
– Mohammad Karmi
Dec 31 '18 at 9:49
Added another bit to comment on this too
– Caius Jard
Dec 31 '18 at 9:52
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53985800%2fbufferedreader-amount-of-bytes-read%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Take a look at BufferedReader javadoc:
Reads text from a character-input stream, buffering characters so as to provide for the efficient reading of characters, arrays, and lines.
The buffer size may be specified, or the default size may be used. The default is large enough for most purposes.
In general, each read request made of a Reader causes a corresponding read request to be made of the underlying character or byte stream. It is therefore advisable to wrap a BufferedReader around any Reader whose read() operations may be costly, such as FileReaders and InputStreamReaders. For example,
BufferedReader in
= new BufferedReader(new FileReader("foo.in"));
will buffer the input from the specified file. Without buffering, each invocation of read() or readLine() could cause bytes to be read from the file, converted into characters, and then returned, which can be very inefficient.
Programs that use DataInputStreams for textual input can be localized by replacing each DataInputStream with an appropriate BufferedReader.
So it buffers the data beforehand from the underlying resource and consequent read instructions use the buffer for efficiency.
Yes it buffers the input but we arguing on the amount stored at a time , just to make it clear with the question. the buffering will be done on large block not 2bytes at time.
– Mohammad Karmi
Dec 31 '18 at 9:56
Read the second line again: It's size could be default which suits most apps or it can be specified.
– Masked Man
Dec 31 '18 at 10:44
add a comment |
Take a look at BufferedReader javadoc:
Reads text from a character-input stream, buffering characters so as to provide for the efficient reading of characters, arrays, and lines.
The buffer size may be specified, or the default size may be used. The default is large enough for most purposes.
In general, each read request made of a Reader causes a corresponding read request to be made of the underlying character or byte stream. It is therefore advisable to wrap a BufferedReader around any Reader whose read() operations may be costly, such as FileReaders and InputStreamReaders. For example,
BufferedReader in
= new BufferedReader(new FileReader("foo.in"));
will buffer the input from the specified file. Without buffering, each invocation of read() or readLine() could cause bytes to be read from the file, converted into characters, and then returned, which can be very inefficient.
Programs that use DataInputStreams for textual input can be localized by replacing each DataInputStream with an appropriate BufferedReader.
So it buffers the data beforehand from the underlying resource and consequent read instructions use the buffer for efficiency.
Yes it buffers the input but we arguing on the amount stored at a time , just to make it clear with the question. the buffering will be done on large block not 2bytes at time.
– Mohammad Karmi
Dec 31 '18 at 9:56
Read the second line again: It's size could be default which suits most apps or it can be specified.
– Masked Man
Dec 31 '18 at 10:44
add a comment |
Take a look at BufferedReader javadoc:
Reads text from a character-input stream, buffering characters so as to provide for the efficient reading of characters, arrays, and lines.
The buffer size may be specified, or the default size may be used. The default is large enough for most purposes.
In general, each read request made of a Reader causes a corresponding read request to be made of the underlying character or byte stream. It is therefore advisable to wrap a BufferedReader around any Reader whose read() operations may be costly, such as FileReaders and InputStreamReaders. For example,
BufferedReader in
= new BufferedReader(new FileReader("foo.in"));
will buffer the input from the specified file. Without buffering, each invocation of read() or readLine() could cause bytes to be read from the file, converted into characters, and then returned, which can be very inefficient.
Programs that use DataInputStreams for textual input can be localized by replacing each DataInputStream with an appropriate BufferedReader.
So it buffers the data beforehand from the underlying resource and consequent read instructions use the buffer for efficiency.
Take a look at BufferedReader javadoc:
Reads text from a character-input stream, buffering characters so as to provide for the efficient reading of characters, arrays, and lines.
The buffer size may be specified, or the default size may be used. The default is large enough for most purposes.
In general, each read request made of a Reader causes a corresponding read request to be made of the underlying character or byte stream. It is therefore advisable to wrap a BufferedReader around any Reader whose read() operations may be costly, such as FileReaders and InputStreamReaders. For example,
BufferedReader in
= new BufferedReader(new FileReader("foo.in"));
will buffer the input from the specified file. Without buffering, each invocation of read() or readLine() could cause bytes to be read from the file, converted into characters, and then returned, which can be very inefficient.
Programs that use DataInputStreams for textual input can be localized by replacing each DataInputStream with an appropriate BufferedReader.
So it buffers the data beforehand from the underlying resource and consequent read instructions use the buffer for efficiency.
answered Dec 31 '18 at 9:36
Masked ManMasked Man
8511617
8511617
Yes it buffers the input but we arguing on the amount stored at a time , just to make it clear with the question. the buffering will be done on large block not 2bytes at time.
– Mohammad Karmi
Dec 31 '18 at 9:56
Read the second line again: It's size could be default which suits most apps or it can be specified.
– Masked Man
Dec 31 '18 at 10:44
add a comment |
Yes it buffers the input but we arguing on the amount stored at a time , just to make it clear with the question. the buffering will be done on large block not 2bytes at time.
– Mohammad Karmi
Dec 31 '18 at 9:56
Read the second line again: It's size could be default which suits most apps or it can be specified.
– Masked Man
Dec 31 '18 at 10:44
Yes it buffers the input but we arguing on the amount stored at a time , just to make it clear with the question. the buffering will be done on large block not 2bytes at time.
– Mohammad Karmi
Dec 31 '18 at 9:56
Yes it buffers the input but we arguing on the amount stored at a time , just to make it clear with the question. the buffering will be done on large block not 2bytes at time.
– Mohammad Karmi
Dec 31 '18 at 9:56
Read the second line again: It's size could be default which suits most apps or it can be specified.
– Masked Man
Dec 31 '18 at 10:44
Read the second line again: It's size could be default which suits most apps or it can be specified.
– Masked Man
Dec 31 '18 at 10:44
add a comment |
The point he's making is that FileInputStream reads N bytes at a time and takes no interest in the data it reads. BufferedReader eventually uses FileInputStream (when reading a file) and does the repetitive read part but it does take an interest in the bytes it reads, treating them as character data (encoding considerations etc) chopping them up into lines
Sure, you can write your own, and not use BufferedReader, but you can say the same about anything in computing: "I didn't like NVidia's display driver, so I sat down and spent 3 years writing my own. Now I'm starting a new operating system. Be done for when quantum computers are mainstream" - nearly no-one does this; it's called reinventing the wheel and there's a reason why we don't do it: for the most part, the wheels other people invented are already fine for our purposes/better than we have time to do ourselves
Note; you seem to be taking issue with the assertion that BufferedReader ultimately reads from the data source a byte or two at a time. It probably doesn't, but I don't think that's the point the guy is making (the language used in the post is rather vague). Regardless of how it reads bytes from an InputStream/Reader, a BufferedReader will certainly inspect the data that it reads on a character-by-character basis as it looks for newlines, so it can make ReadLine() work. It will do this independently of the strategy that it uses to read the file (maybe it repeatedly reads in 4096 byte chunks, but it will certainly have to process the data byte by byte as it interprets it)
Ultimately consider that file access is cached and coalescing of reads may occur at many levels: calling ReaderX.Read() will almost certainly not cause a hard disk to stop everything it's doing, go to a certain sector, read a single byte, and go back to what it was doing before. You might thus issue a million calls to Read() one char that cause no more hard disk thrashing than a single call to Read() into a megabyte buffer
1
you are saying that bufferedreader does repetitive part of reading bytes ? I don't think so, the idea of buffered reader to reduce the access to disk which will read one large block at a time.
– Mohammad Karmi
Dec 31 '18 at 9:45
Edited to add a comment on this
– Caius Jard
Dec 31 '18 at 9:46
ok got it , that what I was looking for :) , I know that the 16 bit need to be interpreted to a valid character but ofcourse not reading 16bit each time
– Mohammad Karmi
Dec 31 '18 at 9:49
Added another bit to comment on this too
– Caius Jard
Dec 31 '18 at 9:52
add a comment |
The point he's making is that FileInputStream reads N bytes at a time and takes no interest in the data it reads. BufferedReader eventually uses FileInputStream (when reading a file) and does the repetitive read part but it does take an interest in the bytes it reads, treating them as character data (encoding considerations etc) chopping them up into lines
Sure, you can write your own, and not use BufferedReader, but you can say the same about anything in computing: "I didn't like NVidia's display driver, so I sat down and spent 3 years writing my own. Now I'm starting a new operating system. Be done for when quantum computers are mainstream" - nearly no-one does this; it's called reinventing the wheel and there's a reason why we don't do it: for the most part, the wheels other people invented are already fine for our purposes/better than we have time to do ourselves
Note; you seem to be taking issue with the assertion that BufferedReader ultimately reads from the data source a byte or two at a time. It probably doesn't, but I don't think that's the point the guy is making (the language used in the post is rather vague). Regardless of how it reads bytes from an InputStream/Reader, a BufferedReader will certainly inspect the data that it reads on a character-by-character basis as it looks for newlines, so it can make ReadLine() work. It will do this independently of the strategy that it uses to read the file (maybe it repeatedly reads in 4096 byte chunks, but it will certainly have to process the data byte by byte as it interprets it)
Ultimately consider that file access is cached and coalescing of reads may occur at many levels: calling ReaderX.Read() will almost certainly not cause a hard disk to stop everything it's doing, go to a certain sector, read a single byte, and go back to what it was doing before. You might thus issue a million calls to Read() one char that cause no more hard disk thrashing than a single call to Read() into a megabyte buffer
1
you are saying that bufferedreader does repetitive part of reading bytes ? I don't think so, the idea of buffered reader to reduce the access to disk which will read one large block at a time.
– Mohammad Karmi
Dec 31 '18 at 9:45
Edited to add a comment on this
– Caius Jard
Dec 31 '18 at 9:46
ok got it , that what I was looking for :) , I know that the 16 bit need to be interpreted to a valid character but ofcourse not reading 16bit each time
– Mohammad Karmi
Dec 31 '18 at 9:49
Added another bit to comment on this too
– Caius Jard
Dec 31 '18 at 9:52
add a comment |
The point he's making is that FileInputStream reads N bytes at a time and takes no interest in the data it reads. BufferedReader eventually uses FileInputStream (when reading a file) and does the repetitive read part but it does take an interest in the bytes it reads, treating them as character data (encoding considerations etc) chopping them up into lines
Sure, you can write your own, and not use BufferedReader, but you can say the same about anything in computing: "I didn't like NVidia's display driver, so I sat down and spent 3 years writing my own. Now I'm starting a new operating system. Be done for when quantum computers are mainstream" - nearly no-one does this; it's called reinventing the wheel and there's a reason why we don't do it: for the most part, the wheels other people invented are already fine for our purposes/better than we have time to do ourselves
Note; you seem to be taking issue with the assertion that BufferedReader ultimately reads from the data source a byte or two at a time. It probably doesn't, but I don't think that's the point the guy is making (the language used in the post is rather vague). Regardless of how it reads bytes from an InputStream/Reader, a BufferedReader will certainly inspect the data that it reads on a character-by-character basis as it looks for newlines, so it can make ReadLine() work. It will do this independently of the strategy that it uses to read the file (maybe it repeatedly reads in 4096 byte chunks, but it will certainly have to process the data byte by byte as it interprets it)
Ultimately consider that file access is cached and coalescing of reads may occur at many levels: calling ReaderX.Read() will almost certainly not cause a hard disk to stop everything it's doing, go to a certain sector, read a single byte, and go back to what it was doing before. You might thus issue a million calls to Read() one char that cause no more hard disk thrashing than a single call to Read() into a megabyte buffer
The point he's making is that FileInputStream reads N bytes at a time and takes no interest in the data it reads. BufferedReader eventually uses FileInputStream (when reading a file) and does the repetitive read part but it does take an interest in the bytes it reads, treating them as character data (encoding considerations etc) chopping them up into lines
Sure, you can write your own, and not use BufferedReader, but you can say the same about anything in computing: "I didn't like NVidia's display driver, so I sat down and spent 3 years writing my own. Now I'm starting a new operating system. Be done for when quantum computers are mainstream" - nearly no-one does this; it's called reinventing the wheel and there's a reason why we don't do it: for the most part, the wheels other people invented are already fine for our purposes/better than we have time to do ourselves
Note; you seem to be taking issue with the assertion that BufferedReader ultimately reads from the data source a byte or two at a time. It probably doesn't, but I don't think that's the point the guy is making (the language used in the post is rather vague). Regardless of how it reads bytes from an InputStream/Reader, a BufferedReader will certainly inspect the data that it reads on a character-by-character basis as it looks for newlines, so it can make ReadLine() work. It will do this independently of the strategy that it uses to read the file (maybe it repeatedly reads in 4096 byte chunks, but it will certainly have to process the data byte by byte as it interprets it)
Ultimately consider that file access is cached and coalescing of reads may occur at many levels: calling ReaderX.Read() will almost certainly not cause a hard disk to stop everything it's doing, go to a certain sector, read a single byte, and go back to what it was doing before. You might thus issue a million calls to Read() one char that cause no more hard disk thrashing than a single call to Read() into a megabyte buffer
edited Dec 31 '18 at 9:50
answered Dec 31 '18 at 9:42
Caius JardCaius Jard
11.7k21239
11.7k21239
1
you are saying that bufferedreader does repetitive part of reading bytes ? I don't think so, the idea of buffered reader to reduce the access to disk which will read one large block at a time.
– Mohammad Karmi
Dec 31 '18 at 9:45
Edited to add a comment on this
– Caius Jard
Dec 31 '18 at 9:46
ok got it , that what I was looking for :) , I know that the 16 bit need to be interpreted to a valid character but ofcourse not reading 16bit each time
– Mohammad Karmi
Dec 31 '18 at 9:49
Added another bit to comment on this too
– Caius Jard
Dec 31 '18 at 9:52
add a comment |
1
you are saying that bufferedreader does repetitive part of reading bytes ? I don't think so, the idea of buffered reader to reduce the access to disk which will read one large block at a time.
– Mohammad Karmi
Dec 31 '18 at 9:45
Edited to add a comment on this
– Caius Jard
Dec 31 '18 at 9:46
ok got it , that what I was looking for :) , I know that the 16 bit need to be interpreted to a valid character but ofcourse not reading 16bit each time
– Mohammad Karmi
Dec 31 '18 at 9:49
Added another bit to comment on this too
– Caius Jard
Dec 31 '18 at 9:52
1
1
you are saying that bufferedreader does repetitive part of reading bytes ? I don't think so, the idea of buffered reader to reduce the access to disk which will read one large block at a time.
– Mohammad Karmi
Dec 31 '18 at 9:45
you are saying that bufferedreader does repetitive part of reading bytes ? I don't think so, the idea of buffered reader to reduce the access to disk which will read one large block at a time.
– Mohammad Karmi
Dec 31 '18 at 9:45
Edited to add a comment on this
– Caius Jard
Dec 31 '18 at 9:46
Edited to add a comment on this
– Caius Jard
Dec 31 '18 at 9:46
ok got it , that what I was looking for :) , I know that the 16 bit need to be interpreted to a valid character but ofcourse not reading 16bit each time
– Mohammad Karmi
Dec 31 '18 at 9:49
ok got it , that what I was looking for :) , I know that the 16 bit need to be interpreted to a valid character but ofcourse not reading 16bit each time
– Mohammad Karmi
Dec 31 '18 at 9:49
Added another bit to comment on this too
– Caius Jard
Dec 31 '18 at 9:52
Added another bit to comment on this too
– Caius Jard
Dec 31 '18 at 9:52
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53985800%2fbufferedreader-amount-of-bytes-read%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
That does not sound correct. A file (on disc) is typically read a sector at a time (usually around 4k) and OSs typically buffer ahead and read more. So 2 or 4 bytes at a time sounds way off.
– markspace
Dec 31 '18 at 9:34
@markspace so shouldn't the buffered reader read one large block ?
– Mohammad Karmi
Dec 31 '18 at 9:36
Despite the many upvotes of that answer, this is clearly wrong.
– Henry
Dec 31 '18 at 9:36
2
The OS uses its own buffers. The only advantage to a Java buffer would be, I think, to reduce the number of OS calls to read data, but that's between the OS and Java, not the file itself.
– markspace
Dec 31 '18 at 9:37