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??
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
}
}
is.close();// baglantiyi kapat
} catch(IOException e) {
System.err.println(e);
}
// here i write a.raw file but the bDizi cannat be resolved.
Why??
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"
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);
}
// 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);
}
ASKER
i want to copy b.raw to a.raw but readşng and again writing them
could u help me?
could u help me?
do you need only read b.raw and copy it exactly to a.raw ?
ASKER
i mean that both using reading and writing i want to copy b.raw to a.raw.
pls help me
pls help me
ASKER
yes but a.raw not exist, we will write(create) it.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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. :)
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
you should be familiar with sound file structure
ASKER
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
}
}
is.close();// baglantiyi kapat
} catch(IOException e) {
System.err.println(e);
}
try {
int okunanByteSayisi ;
fos = new FileOutputStream("b.raw");
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("Kapatm
}
}
}