vahid-p
سه شنبه 05 شهریور 1392, 17:32 عصر
سلام دوستان
یه دانلودر ساده نوشتم که کار میکنه ولی آخر سر میبینی فایل ناقص دانلود شده!
اول این عکس رو ببینید :
109790
خب تو این عکس لینک و محل ذخیره رو مشخص میکنیم. رو لینکی دومی مثلا کلیک میکنم و start میزنم سریع دانلود میشه و 100 درصد که شد، آخرش میبینی فایل ناقص دانلود شده. حتی فایل zip، یعنی لینک اولی، نوشته 554 کیلوبایت ولی وقتی دانلود میکنه میبینی 600 و خورده ای شده و فایل ناقصه.
خلاصه چندین بار که امتحان کردم همین مشکل رو داره. مطمئنا ایراد از کدش هست.
اینم کد قسمت دانلودش :
new Thread(new Runnable() {
@Override
public void run() {
FileOutputStream fout = null;
InputStream input = null;
try {
long fileSize;
URL url=new URL((String)(jTable2.getValueAt(jTable2.getSelecte dRow(), 4)));
URLConnection connection;
connection = url.openConnection();
connection.connect();
fileSize=connection.getContentLength();
input=new BufferedInputStream(connection.getInputStream());
fout=new FileOutputStream(new File(filelocationAddress));
byte[] data=new byte[1024];
long downloaded=0;
int byteDownloadedinThisCycle=0;
while((byteDownloadedinThisCycle=input.read(data)) !=-1){
fout.write(data);
downloaded+=byteDownloadedinThisCycle;
jTable2.setValueAt("%"+(downloaded*100)/fileSize, jTable2.getSelectedRow(), 1);
}
fout.flush();
} catch (IOException ex) {
Logger.getLogger(MainPage.class.getName()).log(Lev el.SEVERE, null, ex);
}finally{
try {
fout.close();
input.close();
} catch (IOException ex) {
Logger.getLogger(MainPage.class.getName()).log(Lev el.SEVERE, null, ex);
}
}
}
}).start();
یه دانلودر ساده نوشتم که کار میکنه ولی آخر سر میبینی فایل ناقص دانلود شده!
اول این عکس رو ببینید :
109790
خب تو این عکس لینک و محل ذخیره رو مشخص میکنیم. رو لینکی دومی مثلا کلیک میکنم و start میزنم سریع دانلود میشه و 100 درصد که شد، آخرش میبینی فایل ناقص دانلود شده. حتی فایل zip، یعنی لینک اولی، نوشته 554 کیلوبایت ولی وقتی دانلود میکنه میبینی 600 و خورده ای شده و فایل ناقصه.
خلاصه چندین بار که امتحان کردم همین مشکل رو داره. مطمئنا ایراد از کدش هست.
اینم کد قسمت دانلودش :
new Thread(new Runnable() {
@Override
public void run() {
FileOutputStream fout = null;
InputStream input = null;
try {
long fileSize;
URL url=new URL((String)(jTable2.getValueAt(jTable2.getSelecte dRow(), 4)));
URLConnection connection;
connection = url.openConnection();
connection.connect();
fileSize=connection.getContentLength();
input=new BufferedInputStream(connection.getInputStream());
fout=new FileOutputStream(new File(filelocationAddress));
byte[] data=new byte[1024];
long downloaded=0;
int byteDownloadedinThisCycle=0;
while((byteDownloadedinThisCycle=input.read(data)) !=-1){
fout.write(data);
downloaded+=byteDownloadedinThisCycle;
jTable2.setValueAt("%"+(downloaded*100)/fileSize, jTable2.getSelectedRow(), 1);
}
fout.flush();
} catch (IOException ex) {
Logger.getLogger(MainPage.class.getName()).log(Lev el.SEVERE, null, ex);
}finally{
try {
fout.close();
input.close();
} catch (IOException ex) {
Logger.getLogger(MainPage.class.getName()).log(Lev el.SEVERE, null, ex);
}
}
}
}).start();