Jo moin, also ich hab mir grad nen kleinen download thread geschrieben der eine datei runterläd, und bei mp3 datein kommt da irgendwie ein knacken rein.
der thread sieht wie folgt aus
der thread sieht wie folgt aus
Code:
package de.bazzdee.sidow;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URLConnection;
public class downloadThread extends Thread{
private InputStream in;
private OutputStream out;
private URLConnection conn;
private sidowGui gui;
private long bytesLoaded = 0;
private static int bufSize = 1024;
private byte[] buffer = new byte[bufSize];
public downloadThread(String filename, URLConnection connection, sidowGui gui) throws IOException {
conn = connection;
this.gui = gui;
File file = new File(filename);
out = (OutputStream)new FileOutputStream(file);
in = conn.getInputStream();
}
public void run() {
int len;
try {
len = in.read(buffer);
if (len > 0) {
out.write(buffer);
bytesLoaded = bytesLoaded + len;
gui.update(bytesLoaded);
}
else {
System.exit(0);
}
} catch (IOException e) {
System.out.println(e.getMessage());
System.exit(0);
}
}
}[quote][/quote]