2012-05-30 50 views
0

我在这,如果我有任何异常,将其写入到一个文件(文件存储在设备内部存储器).....现在我想知道,如果一个Android应用程序它可能发送这个文件到我的本地主机服务器。Android的发送文本文件到服务器

在此先感谢

编辑:下面的代码是什么,我用它来上传图片...

try { 

     ByteArrayOutputStream bos = new ByteArrayOutputStream(); 
     Bitmap bm=bitmap; 
     bm.compress(CompressFormat.PNG, 75, bos); 

     byte[] data = bos.toByteArray(); 

     HttpClient httpClient = new DefaultHttpClient(); 
     String url="192.168.1.1**"; 
     HttpPost postRequest = new HttpPost(url+"uploadimage"); 

     ByteArrayBody bab = new ByteArrayBody(data, imageName); 

     MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); 

     reqEntity.addPart("uploadfile", bab); 

     //reqEntity.addPart("photoCaption", new StringBody("sfsdfsdf")); 

     postRequest.setEntity(reqEntity); 

     HttpResponse response = httpClient.execute(postRequest); 

     BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8")); 

     String sResponse; 

     StringBuilder s = new StringBuilder(); 



     while ((sResponse = reader.readLine()) != null) { 

      s = s.append(sResponse); 

     } 

     System.out.println("Response: " + s); 

    } catch (Exception e) { 

     // handle exception here 

     Log.e(e.getClass().getName(), e.getMessage()); 

    } 

同样地,我想上传一个文件(文本文件)。

+0

请告诉我在服务器上的代码? –

回答

1

现在我想知道,如果它可以将此文件发送到我的本地服务器

是的,这是可能的。

看你的原始需求,我想建议你看一看ACRA

相关问题