if (s==null){
try {
String path1= Environment.getExternalStorageDirectory()+"/1507d/info.txt";
File file=new File(path1);
FileInputStream fis = new FileInputStream(file);
BufferedReader br=new BufferedReader(new InputStreamReader(fis));
s=br.readLine();
} catch (Exception e) {
e.printStackTrace();
}
}
System.out.println("=================》》"+s);
Gson gson = new Gson();
Bean bean = gson.fromJson(s, Bean.class);
data = bean.getResult().getData();
System.out.println(data.size()+"=======================");
//做适配
myAdapter = new MyAdapter(MainActivity.this,data);
listView.setAdapter(myAdapter);
}
@Override
protected String doInBackground(String... strings) {
try {
String path = strings[0];
URL url=new URL(path);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setConnectTimeout(5000);
connection.setReadTimeout(5000);
int code = connection.getResponseCode();
if (code==200){
InputStream is = connection.getInputStream();
String str = MyUtil.getStr(is);
System.out.println("==================="+str);
String path1= Environment.getExternalStorageDirectory()+"/1507d/info.txt";
File file=new File(path1);
file.createNewFile();
FileOutputStream os = new FileOutputStream(file);
os.write(str.getBytes());
os.flush();
return str;
}