Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #22725

Re: hello here is a copy of a copy program on the net .

From Eric Sosman <esosman@comcast-dot-net.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: hello here is a copy of a copy program on the net .
Date 2013-03-05 12:01 -0500
Organization A noiseless patient Spider
Message-ID <kh58av$e3u$1@dont-email.me> (permalink)
References <026b0609-ef87-470e-b899-fc00529bb4ce@googlegroups.com>

Show all headers | View raw


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

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

hello here is a copy of a copy program on the net . giovannich1965@gmail.com - 2013-03-05 08:44 -0800
  Re: hello here is a copy of a copy program on the net . "John B. Matthews" <nospam@nospam.invalid> - 2013-03-05 11:56 -0500
  Re: hello here is a copy of a copy program on the net . Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-03-05 12:01 -0500
  Re: hello here is a copy of a copy program on the net . giovannich1965@gmail.com - 2013-03-05 11:20 -0800
    Re: hello here is a copy of a copy program on the net . Lew <lewbloch@gmail.com> - 2013-03-05 15:50 -0800
  Re: hello here is a copy of a copy program on the net . giovannich1965@gmail.com - 2013-03-05 11:21 -0800
  Re: hello here is a copy of a copy program on the net . giovannich1965@gmail.com - 2013-03-06 12:40 -0800

csiph-web