2013-02-20 27 views
0

此代碼應該將文本文件中的數據發送到服務器。但它只發送第一行。如何移動到android中的下一行文本文件。發送後我想刪除該行。 基本上我想根據它們存儲的順序來發送記錄。使用文本文件將位置信息發送到服務器

File file = new File(Environment.getExternalStorageDirectory(),"/BPCLTracker1/gpsdata.txt"); 
    File f1=new File(Environment.getExternalStorageDirectory(),"/BPCLTracker1/gpsdata.txt"); 
    RandomAccessFile in = null; 
    RandomAccessFile in1 = null; 
    try 
    { 
     in = new RandomAccessFile(file, "rw"); 
     in1= new RandomAccessFile(f1, "rw");} 
     catch (FileNotFoundException e) 
     {// TODO Auto-generated catch bloc e.printStackTrace();} 
     String line ="0"; 
     while (true) 
     { 
     try 
     { 
      if (isInternetOn()) 
      { 
       while ((line = in.readLine()) != null) 
       { 
        HttpEntity entity; 
        HttpClient client = new DefaultHttpClient(); 
        String url = "some url is here"; 
        HttpPost request = new HttpPost(url); 
        StringEntity se = new StringEntity(line); 
        se.setContentEncoding("UTF-8"); 
        se.setContentEncoding(new BasicHeader(
        HTTP.CONTENT_TYPE, "application/json")); 
        entity = se; 
        request.setEntity(entity); 
        HttpResponse response = client.execute(request); 
        entity = response.getEntity(); 
        if (entity != null) {} 
       } 
      } 
     } 
    } 

謝謝

+0

您的代碼在運行時是否捕獲到任何異常? – 2013-02-20 05:25:01

回答

0

上傳你的文件這樣

HttpClient的客戶端=新DefaultHttpClient(); HttpPost post = new HttpPost(url);

MultipartEntity entity = new MultipartEntity(); entity.addPart(「file」,new FileBody(file)); post.setEntity(entity);

HttpResponse response = httpclient.execute(post);

相關問題