Questo è il metodo sendFile
codice:public void sendFile(File f) throws IOException { long dimensioneFile = f.length(); // inizializzo GUI con progress bar --> GUItrasferimento = new GUItrasferimento(this.GUIBROWSE_LOC, false, this); GUItrasferimento.setVisible(true); //GUItrasferimento.jLabel6.setText(DEST_DIR); GUItrasferimento.jLabel7.setText(0+" kb /"); GUItrasferimento.jLabel8.setText(dimensioneFile +" kb"); // <--- FileInputStream fis = null; try { fis = new FileInputStream(f.getPath()); byte[] buf = new byte[1024]; int read; long progresso=0; int tot=0; while ((read = fis.read(buf)) != -1 ) { tot+=read; // dim : 100% = tot : x //System.out.println("Progresso: "+progresso+"%"); progresso = (tot*100)/dimensioneFile; GUItrasferimento.jProgressBar1.setValue((int)progresso); GUItrasferimento.jLabel7.setText(tot+" kb /"); OOS.write(buf, 0, read); } OOS.writeObject("ARRIVED"); OOS.flush(); GUItrasferimento.jButton2.setText("Ok"); interrompi = false; } catch (FileNotFoundException ex) { Logger.getLogger(browse.class.getName()).log(Level.SEVERE, null, ex); } finally { try { fis.close(); } catch (IOException ex) { Logger.getLogger(browse.class.getName()).log(Level.SEVERE, null, ex); } } }

Rispondi quotando
