Amin-rz
یک شنبه 20 مهر 1393, 19:18 عصر
سلام.
من با این کد یه txt رو از نت می خونم :
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpGet httppost = new HttpGet("http://www.smsbaaz.ir/admin/smsbaaz/smsbaaz.txt");
HttpResponse response = null;
try {
response = httpclient.execute(httppost);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
HttpEntity ht = response.getEntity();
BufferedHttpEntity buf = null;
try {
buf = new BufferedHttpEntity(ht);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
InputStream is = null;
try {
is = buf.getContent();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
BufferedReader r = new BufferedReader(new InputStreamReader(is));
StringBuilder total = new StringBuilder();
String line;
try {
while ((line = r.readLine()) != null) {
total.append(line + "\n");
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String smsbaaz = total.toString();
باید مطمئن بشم که متن به طور کامل لود شده بعد کارهای بعدی رو انجام بدم.
چطور میشه مطمئن شد؟
مثلا وقتی مشکلی پیش میاد و نمیتونه txt رو از نت بگیره به جاش متن : <HTML></HTML> رو بر می گردونه.
من با این کد یه txt رو از نت می خونم :
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpGet httppost = new HttpGet("http://www.smsbaaz.ir/admin/smsbaaz/smsbaaz.txt");
HttpResponse response = null;
try {
response = httpclient.execute(httppost);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
HttpEntity ht = response.getEntity();
BufferedHttpEntity buf = null;
try {
buf = new BufferedHttpEntity(ht);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
InputStream is = null;
try {
is = buf.getContent();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
BufferedReader r = new BufferedReader(new InputStreamReader(is));
StringBuilder total = new StringBuilder();
String line;
try {
while ((line = r.readLine()) != null) {
total.append(line + "\n");
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String smsbaaz = total.toString();
باید مطمئن بشم که متن به طور کامل لود شده بعد کارهای بعدی رو انجام بدم.
چطور میشه مطمئن شد؟
مثلا وقتی مشکلی پیش میاد و نمیتونه txt رو از نت بگیره به جاش متن : <HTML></HTML> رو بر می گردونه.