Posted By:
David_Thornton
Posted On:
Wednesday, May 12, 2004 06:43 PM
An MP3 file is a byte stream not a character stream so you should not be reading it using BufferedReader.readLine() method. I doubt there are any new line characters in an MP3 file that are actually meant to be.
You are also using the BufferedReader as a wrapper for an InputStreamReader. An InputStreamReader reads bytes and converts them to characters using the default or specified character encoding.
What you need to do is just read and write raw bytes.
Your code should probably be along these lines;
try {
URL u = new URL(url);
URLConnection ucon = u.openConnection();
FileWriter mp3Writer = new FileWriter("first.mp3");
InputStream in = ucon.getInputStream();
int b = 0;
while ((b = in.read())!= -1) {
mp3Writer.write(b);
}
mp3Writer.flush();
mp3Writer.close();
}
catch (Exception e){
System.out.println(e);
}