1 Reply Latest reply on Oct 24, 2008 8:29 AM by thomas_behr

    problem in character stream...sound is distorted

    807589
      hi friends,
      I have made a file copy program on audio file(mp3).

      its likely succeeded but the destination file give the distorted sound. I have used the character stream to make it done.
      however, it was not a problem using byte streams before few days.
      below is program
      import java.io.*;
      
      
      public class CopyBytes {
          public static void main(String[] args) throws IOException {
              BufferedReader in = null;
              BufferedWriter out = null;
              char []buff=new char[20000];
              int ch=0,length=30;
              try {
                  in = new BufferedReader(new FileReader("1.mp3"));
                  out = new BufferedWriter(new FileWriter("2.mp3"));       
            
                for(;ch!=-1;)
                 {
                  while ((ch=in.read(buff,0,20000))!=-1) {
      
                        //System.out.format("%s\n\n break\n",new String(buff));
                          
                        out.write(buff,0,20000);
                         break;                
                    
                     
                   }
                
                 }
      
              } finally {
                  if (in != null) {
                      in.close();
                  }
                  if (out != null) {
                      out.close();
                  }
              }
          }
      }
      although there was not use of two loops, actually i was making file splitter program and got this situation accordingly

      any analysis on distorted sound?
        • 1. Re: problem in character stream...sound is distorted
          thomas_behr
          san_4u wrote:
          I have used the character stream to make it done.
          Why? Clearly, you are not working with text files, so you shouldn't use FileReader/FileWriter at all, but work with streams and bytes. AFAIK, FileReader/FileWriter may perform special operation on the input/output due to character encodings, which you definitely don't want to happen with non-text files (as e.g. MP3 encoded audio files).