Santai aja namanya juga belajar, pasti ada bagian susahnya ;)

BTW, gue lupa elo ada makai IO library.. Bagian yang ada sangkut
pautnya ama IO juga sebaiknya di wrap di dalam class Runnable and
dijalanin di dalam Thread :)

Jadi elo harus nambah 1 thread lagi disamping Thread yg buat
ProgressBar elo okay? ;) 

Total ada 2 threads
1 Thread buat Runnable ProgressBar
1 Thread lagi buat IO System  (File, InputStreamReader, etc...)

=================================================
Bungkus proses di bawah ini dalam Runnable class
dan jalanin di dalam Thread. 
=================================================
File file = fc.getSelectedFile();
long filesize = file.length();

ClientSession cs = (ClientSession) OBEXConnector.open(adrProto);
HeaderSet hs = cs.connect(cs.createHeaderSet());
byte objek[] = getBytesFromFile(file);
hs.setHeader(HeaderSet.NAME, file.getName());
hs.setHeader(HeaderSet.TYPE, "text");
Operation po = cs.put(hs);
outputStream = po.openOutputStream();

ByteArrayInputStream bais = new ByteArrayInputStream(objek);
byte[] buffer = new byte[0xFF];
int i = bais.read(buffer);
done = 0;
while (i != -1) {
outputStream.write(buffer, 0, i);
done += i;
progressBar.setValue(done);
i = bais.read(buffer);
}

outputStream.flush();
outputStream.close();
po.close();
===========================================

Regards,

Donny

Kirim email ke