2013-02-20 58 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);

相关问题