亲,怎么向服务器里面写文件?
我有服务器,我想向服务器里面的文件写东西。(通过WAP联网方式)
求思路和代码。
我有服务器,我想向服务器里面的文件写东西。(通过WAP联网方式)
求思路和代码。
解决方案 »
- 请教如何像QQ一样关闭Activity后网络服务仍可继续运行
- 基于百度接口做的自动定位、但每次都要点击好几次才可以
- Flash类手机应用市场人气仅占娱乐类一成
- EditText里面可以显示图片,但是如何复制粘贴呢?
- Android2D的工作原理是什么
- 有关listview中监听button状态,滚动后顺序混乱的问题
- 有使用Android Studio 的兄弟吗?请教一个问题
- Android View 按一定的角度移动
- 模拟器安装apk失败 Installation error: INSTALL_FAILED_CONTAINER_ERROR
- 网页端如何实现手机(通过无线wifi)控制电视,主要包括哪几块功能模块?
- 再发一贴:问framework里的代码是怎么运行的?
- android 的一个bug,不知道有何解决办法?
就是Android客户端与服务端通讯的问题。去google一下吧
然后android发起http连接,如果你写的内容比较大或者是二进制的话,那么就要用post的方式,二进制的话应该要先把内容base64吧,然后建立http后就可以跟其他流一样write了
服务器上打开ftp服务,写权限也打开。android使用ftp上传文件到服务器。百度或谷歌下android ftp。
服务器打开ftp服务,写权限也打开。android端使用ftp上传文件到ftp服务器。百度或谷歌搜索下android ftp
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());
}
ByteArrayOutputStream bytestream = new ByteArrayOutputStream();
int ch;
while ((ch = iStrm.read()) != -1)
{
bytestream.write(ch);
}
byte imgdata[]=bytestream.toByteArray();
bytestream.close();
return imgdata;
}