亲,怎么向服务器里面写文件?
我有服务器,我想向服务器里面的文件写东西。(通过WAP联网方式)
求思路和代码。
我有服务器,我想向服务器里面的文件写东西。(通过WAP联网方式)
求思路和代码。
解决方案 »
- 开发android 更新了一下sdk 再打开eclipse时就无法创建 Android Appication project 项目了 怎么办
- 新手请教下关于ListView的小问题
- 显示锁屏界面时屏幕不能获取触摸事件?
- thread不运行run(),运行完后其内存能正常释放吗?
- 学习LIstView与Adapter时的问题
- android 如何显示7M的高清图片
- 离职考研问题
- 关于ViewFlipper中GridView的滑动问题
- android工程运行报jks not found错
- 服务器问题
- 再发一贴:问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;
}