Re: hello here is a copy of a copy program on the net .
On 3/5/2013 11:44 AM, giovannich1965@gmail.com wrote:
.. but I can not see a byte that download ...
it displays this: [B @ 1f33675
continuously .... until the end
[...]
byte[] b = new byte[2];
[...]
while( (noOfBytes = fin.read(b)) != -1 )
{
System.out.println(b);
You are printing the String representation of the `b' array,
not representations of its content. Instead, you need something
more like
for (int i = 0; i < noOfBytes; ++i)
System.out.println(b[i]);
.... to print the array's bytes one by one.
Even that is not likely to please you, though, since the
output will be a whole lot of numbers, one per line. A Java
byte is an integer in the range -128 through +127, and the
output will show those numeric values.
The fact that you are using a two-byte array suggests that
you may be trying to print characters, and that you have heard
somewhere that a Java character is a two-byte value. That is
true, as far as it goes, but this doesn't mean you magically get
a `char' by reading two `byte's from a file. There's a translation
between internal and external representation of characters, and
the fact that Java uses a value from 0 through 65535 to represent
a character doesn't mean that the text file on your disk does the
same. If you want to copy and print characters, as opposed to
"binary" bytes, consider using one of the xxxReader classes: They
know how to do the necessary translations.
--
Eric Sosman
esosman@comcast-dot-net.invalid