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


Groups > comp.lang.java.programmer > #22723 > unrolled thread

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

Started bygiovannich1965@gmail.com
First post2013-03-05 08:44 -0800
Last post2013-03-06 12:40 -0800
Articles 7 — 4 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  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

#22723 — hello here is a copy of a copy program on the net .

Fromgiovannich1965@gmail.com
Date2013-03-05 08:44 -0800
Subjecthello here is a copy of a copy program on the net .
Message-ID<026b0609-ef87-470e-b899-fc00529bb4ce@googlegroups.com>
.. but I can not see a byte that download ... 
it displays this: [B @ 1f33675
  continuously .... until the end

if you can help me thank you ...

package fichier;

import java.io.FileNotFoundException;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
 
 
public class fichier {
 
        public static void main(String[] args) {
               
                String strSourceFile="C:/temp/demo.txt";
                String strDestinationFile="C:/temp/demo2.txt";
               
                try
                {
                        //create FileInputStream object for source file
                        FileInputStream fin = new FileInputStream(strSourceFile);
                       
                        //create FileOutputStream object for destination file
                        FileOutputStream fout = new FileOutputStream(strDestinationFile);
                       
                        byte[] b = new byte[2];
                        int noOfBytes = 0;
                       
                        System.out.println("Copying file using streams");
                       
                        //read bytes from source file and write to destination file
                        while( (noOfBytes = fin.read(b)) != -1 )
                        {
                          System.out.println(b);
                                fout.write(b, 0, noOfBytes);
                        }
                       
                        System.out.println("File copied!");
                       
                        //close the streams
                        fin.close();
                        fout.close();                  
                       
                }
                catch(FileNotFoundException fnf)
                {
                        System.out.println("Specified file not found :" + fnf);
                }
                catch(IOException ioe)
                {
                        System.out.println("Error while copying file :" + ioe);
                }
        }
}
 
/*
Typical output would be
Copying file using streams
File copied!
*/

[toc] | [next] | [standalone]


#22724

From"John B. Matthews" <nospam@nospam.invalid>
Date2013-03-05 11:56 -0500
Message-ID<nospam-B61581.11563905032013@news.aioe.org>
In reply to#22723
In article <026b0609-ef87-470e-b899-fc00529bb4ce@googlegroups.com>,
 giovannich1965@gmail.com wrote:

> I can not see a byte that download ... 
> it displays this: [B @ 1f33675
> continuously .... until the end
[...]

The array of bytes inherits toString() from java.lang.Object.

>   byte[] b = new byte[2];

The method println invokes toString() to display 'a string that 
"textually represents" this object.'

>   System.out.println(b);

You might try one of the java.util.Arrays.toString() variations.

-- 
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>

[toc] | [prev] | [next] | [standalone]


#22725

FromEric Sosman <esosman@comcast-dot-net.invalid>
Date2013-03-05 12:01 -0500
Message-ID<kh58av$e3u$1@dont-email.me>
In reply to#22723
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

[toc] | [prev] | [next] | [standalone]


#22730

Fromgiovannich1965@gmail.com
Date2013-03-05 11:20 -0800
Message-ID<629a4687-24e7-49cc-b8b0-e7f91fbf79bd@googlegroups.com>
In reply to#22723
thank you
display is just a control to see if read
but if I wanted to see how hexaa instead of decimal?
And how to change the value read
for example by inverting the value?

b [i] = - (b [i]);



Le mardi 5 mars 2013 17:44:01 UTC+1, giovann...@gmail.com a écrit :
> .. but I can not see a byte that download ... 
> 
> it displays this: [B @ 1f33675
> 
>   continuously .... until the end
> 
> 
> 
> if you can help me thank you ...
> 
> 
> 
> package fichier;
> 
> 
> 
> import java.io.FileNotFoundException;
> 
> import java.io.FileInputStream;
> 
> import java.io.FileOutputStream;
> 
> import java.io.IOException;
> 
>  
> 
>  
> 
> public class fichier {
> 
>  
> 
>         public static void main(String[] args) {
> 
>                
> 
>                 String strSourceFile="C:/temp/demo.txt";
> 
>                 String strDestinationFile="C:/temp/demo2.txt";
> 
>                
> 
>                 try
> 
>                 {
> 
>                         //create FileInputStream object for source file
> 
>                         FileInputStream fin = new FileInputStream(strSourceFile);
> 
>                        
> 
>                         //create FileOutputStream object for destination file
> 
>                         FileOutputStream fout = new FileOutputStream(strDestinationFile);
> 
>                        
> 
>                         byte[] b = new byte[2];
> 
>                         int noOfBytes = 0;
> 
>                        
> 
>                         System.out.println("Copying file using streams");
> 
>                        
> 
>                         //read bytes from source file and write to destination file
> 
>                         while( (noOfBytes = fin.read(b)) != -1 )
> 
>                         {
> 
>                           System.out.println(b);
> 
>                                 fout.write(b, 0, noOfBytes);
> 
>                         }
> 
>                        
> 
>                         System.out.println("File copied!");
> 
>                        
> 
>                         //close the streams
> 
>                         fin.close();
> 
>                         fout.close();                  
> 
>                        
> 
>                 }
> 
>                 catch(FileNotFoundException fnf)
> 
>                 {
> 
>                         System.out.println("Specified file not found :" + fnf);
> 
>                 }
> 
>                 catch(IOException ioe)
> 
>                 {
> 
>                         System.out.println("Error while copying file :" + ioe);
> 
>                 }
> 
>         }
> 
> }
> 
>  
> 
> /*
> 
> Typical output would be
> 
> Copying file using streams
> 
> File copied!
> 
> */

[toc] | [prev] | [next] | [standalone]


#22734

FromLew <lewbloch@gmail.com>
Date2013-03-05 15:50 -0800
Message-ID<c0a27d29-f02b-460f-bf22-e1fe7c15ef43@googlegroups.com>
In reply to#22730
giovann...@ wrote:
> thank you
> display is just a control to see if read
> but if I wanted to see how hexaa instead of decimal?
> And how to change the value read
> for example by inverting the value?
> 
> b [i] = - (b [i]);

http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#format(java.lang.String, java.lang.Object...)
http://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html#syntax
http://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html

String rep = "";
for ( byte by : b )
{
  rep += String.format( "%2.2x ", by);
}

b [i] = - (b [i]);
is a perfectly valid expression. It has gotchas; the right-hand side is evaluated as an 'int' 
and undergoes a narrowing conversion on the assignment.

--
Lew

[toc] | [prev] | [next] | [standalone]


#22731

Fromgiovannich1965@gmail.com
Date2013-03-05 11:21 -0800
Message-ID<680bb944-c423-4038-a84b-aaccbff28c12@googlegroups.com>
In reply to#22723
thank you
display is just a control to see if read
but if I wanted to see how hexaa instead of decimal?
And how to change the value read
for example by inverting the value?

b [i] = - (b [i]);


ps: escuse me error, translate in english me french me langage


Le mardi 5 mars 2013 17:44:01 UTC+1, giovann...@gmail.com a écrit :
> .. but I can not see a byte that download ... 
> 
> it displays this: [B @ 1f33675
> 
>   continuously .... until the end
> 
> 
> 
> if you can help me thank you ...
> 
> 
> 
> package fichier;
> 
> 
> 
> import java.io.FileNotFoundException;
> 
> import java.io.FileInputStream;
> 
> import java.io.FileOutputStream;
> 
> import java.io.IOException;
> 
>  
> 
>  
> 
> public class fichier {
> 
>  
> 
>         public static void main(String[] args) {
> 
>                
> 
>                 String strSourceFile="C:/temp/demo.txt";
> 
>                 String strDestinationFile="C:/temp/demo2.txt";
> 
>                
> 
>                 try
> 
>                 {
> 
>                         //create FileInputStream object for source file
> 
>                         FileInputStream fin = new FileInputStream(strSourceFile);
> 
>                        
> 
>                         //create FileOutputStream object for destination file
> 
>                         FileOutputStream fout = new FileOutputStream(strDestinationFile);
> 
>                        
> 
>                         byte[] b = new byte[2];
> 
>                         int noOfBytes = 0;
> 
>                        
> 
>                         System.out.println("Copying file using streams");
> 
>                        
> 
>                         //read bytes from source file and write to destination file
> 
>                         while( (noOfBytes = fin.read(b)) != -1 )
> 
>                         {
> 
>                           System.out.println(b);
> 
>                                 fout.write(b, 0, noOfBytes);
> 
>                         }
> 
>                        
> 
>                         System.out.println("File copied!");
> 
>                        
> 
>                         //close the streams
> 
>                         fin.close();
> 
>                         fout.close();                  
> 
>                        
> 
>                 }
> 
>                 catch(FileNotFoundException fnf)
> 
>                 {
> 
>                         System.out.println("Specified file not found :" + fnf);
> 
>                 }
> 
>                 catch(IOException ioe)
> 
>                 {
> 
>                         System.out.println("Error while copying file :" + ioe);
> 
>                 }
> 
>         }
> 
> }
> 
>  
> 
> /*
> 
> Typical output would be
> 
> Copying file using streams
> 
> File copied!
> 
> */

[toc] | [prev] | [next] | [standalone]


#22744

Fromgiovannich1965@gmail.com
Date2013-03-06 12:40 -0800
Message-ID<e646ab16-443b-4270-b30a-6f8d7f496a76@googlegroups.com>
In reply to#22723
I place or that?

while( (noOfBytes = fin.read(b)) != -1 ) 
                        { 
                          System.out.println(b); 
                                fout.write(b, 0, noOfBytes); 
String rep = ""; 
for ( byte by : b ) 
{ 
  rep += String.format( "%2.2x ", by); 
} 

b [i] = - (b [i]); 


                        } 


Le mardi 5 mars 2013 17:44:01 UTC+1, giovann...@gmail.com a écrit :
> .. but I can not see a byte that download ... 
> 
> it displays this: [B @ 1f33675
> 
>   continuously .... until the end
> 
> 
> 
> if you can help me thank you ...
> 
> 
> 
> package fichier;
> 
> 
> 
> import java.io.FileNotFoundException;
> 
> import java.io.FileInputStream;
> 
> import java.io.FileOutputStream;
> 
> import java.io.IOException;
> 
>  
> 
>  
> 
> public class fichier {
> 
>  
> 
>         public static void main(String[] args) {
> 
>                
> 
>                 String strSourceFile="C:/temp/demo.txt";
> 
>                 String strDestinationFile="C:/temp/demo2.txt";
> 
>                
> 
>                 try
> 
>                 {
> 
>                         //create FileInputStream object for source file
> 
>                         FileInputStream fin = new FileInputStream(strSourceFile);
> 
>                        
> 
>                         //create FileOutputStream object for destination file
> 
>                         FileOutputStream fout = new FileOutputStream(strDestinationFile);
> 
>                        
> 
>                         byte[] b = new byte[2];
> 
>                         int noOfBytes = 0;
> 
>                        
> 
>                         System.out.println("Copying file using streams");
> 
>                        
> 
>                         //read bytes from source file and write to destination file
> 
>                         while( (noOfBytes = fin.read(b)) != -1 )
> 
>                         {
> 
>                           System.out.println(b);
> 
>                                 fout.write(b, 0, noOfBytes);
> 
>                         }
> 
>                        
> 
>                         System.out.println("File copied!");
> 
>                        
> 
>                         //close the streams
> 
>                         fin.close();
> 
>                         fout.close();                  
> 
>                        
> 
>                 }
> 
>                 catch(FileNotFoundException fnf)
> 
>                 {
> 
>                         System.out.println("Specified file not found :" + fnf);
> 
>                 }
> 
>                 catch(IOException ioe)
> 
>                 {
> 
>                         System.out.println("Error while copying file :" + ioe);
> 
>                 }
> 
>         }
> 
> }
> 
>  
> 
> /*
> 
> Typical output would be
> 
> Copying file using streams
> 
> File copied!
> 
> */

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web