栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

服务器图片文件列表提取

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

服务器图片文件列表提取

先看看效果

   

利用下拉列表,显示获取的图片文件列表,然后选择图片进行显示

 获取服务器端图片文件列表需要移动端和服务端的双向配合

    1  服务器端代码

    

using Newtonsoft.Json;  //C#中处理JSON

public partial class Default5 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string userFile = "D:\phpstudy_pro\WWW\WebSite2\WxpPic";
            DirectoryInfo root = new DirectoryInfo(userFile);
            FileInfo[] files = root.GetFiles();


            //输出图片文件列表
            Dictionary dic = new Dictionary();
            int iCount=files.Count();
            if (iCount>0)
            {
                for(int i=0;i 

 2  移动端代码

     

//需要一个全局变量数组
 public String[] WxpPicArray2;

//调用函数
//获取图片列表
    private void WxpGetPiclist()
    {
        //获取图片列表
        String url = "http://x.x.x.x/default5.aspx";
        WxpGetNetworkPiclistTask mTask = new WxpGetNetworkPiclistTask();
        mTask.execute(url);
    }

 实现功能的异步线程类  WxpGetNetworkPiclistTask

 //获取网络图片列表异步线程类
    private class WxpGetNetworkPiclistTask extends AsyncTask {

        @Override
        protected void onPostExecute(String result) {
            //最终结果的显示
            //mTvProgress.setText(result);
            tx.setText(result);
            //声明一个下拉列表的数组适配器
            ArrayAdapter starAdapter = new ArrayAdapter(getActivity(),R.layout.item_select,WxpPicArray2);
            //设置数组适配器的布局样式
            starAdapter.setDropDownViewResource(R.layout.item_dropdown);
            //设置下拉框的标题,不设置就没有难看的标题了
            spList.setprompt("请选择图片");
            //设置下拉框的数组适配器
            spList.setAdapter(starAdapter);
            //设置下拉框默认的显示第一项
            spList.setSelection(0);
        }

        @Override
        protected void onPreExecute() {
            //开始前的准备工作
            //mTvProgress.setText("loading...");
            tx.setText("loading .....");
            WxpPicArray2= new String[]{};
        }

        @Override
        protected void onProgressUpdate(Integer... values) {
            //显示进度
            // mPgBar.setProgress(values[0]);
            // mTvProgress.setText("loading..." + values[0] + "%");
            tx.setText("loading:" + values[0] + "%");
        }

        @Override
        protected String doInBackground(String... params) {
            //这里params[0]和params[1]是execute传入的两个参数
            String url = params[0];
            BufferedReader bufferedReader = null;
            try {
                url = url + "";

                tx.setText("位置信息");
                URL httpUrl = new URL(url);
                HttpURLConnection httpURLConnection = (HttpURLConnection) httpUrl.openConnection();
                //设置请求头header
                httpURLConnection.setRequestMethod("GET");
                //设置请求头header
                httpURLConnection.setRequestProperty("test-header", "get-header-value");
                httpURLConnection.setReadTimeout(5000);

                //获取内容
                InputStream inputStream = httpURLConnection.getInputStream();
                bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
                final StringBuffer stringBuffer = new StringBuffer();
                String line = null;
                while ((line = bufferedReader.readLine()) != null) {
                    stringBuffer.append(line);
                }
                //解析JSON
                JSonObject jsonObject = new JSonObject(stringBuffer.toString());
                Iterator it = jsonObject.keys();
                String keys = "";
                String vals = null;
                String sourceStr = "";
                List listPicname=new ArrayList();

                //遍历keys
                while (it.hasNext()) {//遍历JSonObject
                    keys = (String) it.next().toString();
                    // sourceStr = sourceStr + jsonObject.get(keys).toString() + ";";
                    listPicname.add(jsonObject.get(keys).toString());
                }
                WxpPicArray2=listPicname.toArray(new String[listPicname.size()]);

                return "success";

            } catch (Exception e) {
                e.printStackTrace();
                return (e.toString());
            }
        }

    }

 

 

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/313189.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号