Link to home
Start Free TrialLog in
Avatar of dervisakyuz
dervisakyuz

asked on

a simple error

i read a file to an integer array but when i want to write it

like this;

// here i read "b.raw" file

try {
                        InputStream is = new FileInputStream("b.raw");
                        byte[] bDizi = new byte[640];
                        int okunanByteSayisi ;
                        while( (okunanByteSayisi = is.read(bDizi)) != -1 ) {
                              for(int i=0; i<okunanByteSayisi; i++) {
            int      so = bDizi[i];
                                    System.out.println(bDizi[i]  ); // here bDizi doesnt resolved
                              }

                        }
                        is.close();// baglantiyi kapat

                  } catch(IOException e) {
                        System.err.println(e);
                  }



// here i write a.raw file but the bDizi cannat be resolved.


Why??
Avatar of dervisakyuz
dervisakyuz

ASKER

try {
                    InputStream is = new FileInputStream("b.raw");
                    byte[] bDizi = new byte[640];
                    int okunanByteSayisi ;
                    while( (okunanByteSayisi = is.read(bDizi)) != -1 ) {
                         for(int i=0; i<okunanByteSayisi; i++) {
          int     so = bDizi[i];
                              System.out.println(bDizi[i]  ); //not here
                         }

                    }
                    is.close();// baglantiyi kapat

               } catch(IOException e) {
                    System.err.println(e);
               }


try {
                                     
                                     int okunanByteSayisi ;
                                     fos = new FileOutputStream("b.raw"); // dosyaya baglan
                                     for( int i=0;i<okunanByteSayisi;i++) {
                                           
                                           
                                           fos.write(bDizi); // here  bDizi cannot resolved
                                     }
                               } catch (IOException exIo) {
                                     System.err.println("Hata Olustu:"+exIo);
                               } finally {
                                        try {
                                           fos.close(); // baglantiyi kapa
                                     } catch (IOException exClose) {
                                           System.err.println("Kapatmada sorun var:"+exClose);
                                     }  
                               }  
                           
                           
                   }
                   
                  
Avatar of hoomanv
InputStream is = new FileInputStream("b.raw");
fos = new FileOutputStream("b.raw");

why are you reading and writting to the same file ?
you told that the output would be written to "a.raw"
also the write portion of your code does not correspond with the read part

// read
// you are reading the entire file contents, each time filling the array with new data discarding the previous read data

      byte[] bDizi = new byte[640];
      int okunanByteSayisi ;
      while( (okunanByteSayisi = is.read(bDizi)) != -1 ) {
            for(int i=0; i<okunanByteSayisi; i++) {
                  int so = bDizi[i];
                  System.out.println(bDizi[i]);
            }
      }

// write
// you are writing only the last read array, okunanByteSayisi times

      for( int i=0;  i<okunanByteSayisi; i++) {
            fos.write(bDizi);
      }
i want to copy b.raw to a.raw but read&#351;ng and again writing them

could u help me?
do you need only read b.raw and copy it exactly to a.raw ?
i mean that both using reading and writing i want to copy b.raw to a.raw.

pls help me
yes but a.raw not exist, we will write(create) it.

ASKER CERTIFIED SOLUTION
Avatar of hoomanv
hoomanv
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
is there any way to copy exactly  not same.

some missing bytes etc. i need sth like this.

the file i have copied is a sound file.

i will show "a.raw" to  my teacher as  here is the echo cancelled file. :)



you need read the entire file,parse it, make the changes in memory, and then write it to output.
you should be familiar with sound file structure