亲,怎么向服务器里面写文件?
我有服务器,我想向服务器里面的文件写东西。(通过WAP联网方式)
求思路和代码。

解决方案 »

  1.   

    wap联网倒是没尝试过,我之前的项目是通过json数据来写文件什么的信息的,android端把要挟的数据封装成json的数据格式,然后通过Http操作发送到服务器,服务器端再写。
      

  2.   

    用POST 的方式,很好解决。
      

  3.   


     就是Android客户端与服务端通讯的问题。去google一下吧 
      

  4.   

    你先在服务器架个php,然后写个php脚本,在里头将请求的参数写到文件上
    然后android发起http连接,如果你写的内容比较大或者是二进制的话,那么就要用post的方式,二进制的话应该要先把内容base64吧,然后建立http后就可以跟其他流一样write了
      

  5.   

    亲能给一个样例吗?  如果会写php顺便把PHP文件也写了,最重要的是注释,亲,谢谢
      

  6.   


    服务器上打开ftp服务,写权限也打开。android使用ftp上传文件到服务器。百度或谷歌下android ftp。
      

  7.   


    服务器打开ftp服务,写权限也打开。android端使用ftp上传文件到ftp服务器。百度或谷歌搜索下android ftp
      

  8.   

    如果服务器是Asp.net的,可以通过新建一个网页,后台代码如下
    protected void Page_Load(object sender, EventArgs e)
            {
    System.IO.Stream s = Request.InputStream;
    string fileName = DateTime.Now.Ticks.ToString() + ".txt";
    filePath = Server.MapPath("~/Upload/" + fileName + "");//路径 FileStream fs1 = new FileStream(filePath, FileMode.Create, FileAccess.Write);//创建写入文件 
    int i = 0;
    while ((count = s.Read(buffer, 0, 1024)) > 0)
       {
        fs1.Write(buffer, 0, count);
         i += count;
        }
    fs1.Close();
    }
    手机端代码可以如下 String fileName="";//完整的文件名
    URL url;
    try {

    urlConnection = getURLConnection(urlString);

    urlConnection.setDoOutput(true);
    urlConnection.setRequestMethod("POST"); FileInputStream fileInput = new FileInputStream(fileName);
    urlConnection.getOutputStream().write(InputStreamTools.InputStreamToByte(fileInput));
    urlConnection.getOutputStream().flush();
    urlConnection.getOutputStream().close();

    int code = urlConnection.getResponseCode();
    System.out.println("code   " + code); int response = urlConnection.getResponseCode();
    if (response == 200) {
    InputStream in = urlConnection.getInputStream();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    byte[] buff = new byte[1024];
    int rc = 0;
    int mm=1;
    while ((rc = in.read(buff, 0, 1024)) != -1) {
    baos.write(buff, 0, rc);
    Log.i("test",""+mm++);
    }
    byte[] receivedcontent = baos.toByteArray();
    showToast(new String(receivedcontent));
    in.close();
    in = null;
    baos.close();
    baos = null; } else { }
    } catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    showToast("" + e.getMessage());
    }
      

  9.   

    public static byte[] InputStreamToByte(InputStream iStrm) throws IOException {
    ByteArrayOutputStream bytestream = new ByteArrayOutputStream();
    int ch;
    while ((ch = iStrm.read()) != -1)
    {
    bytestream.write(ch);
    }
    byte imgdata[]=bytestream.toByteArray();
    bytestream.close();
    return imgdata;
      

  10.   

    有post的代码吗?简单例子,android的