readLine只读取第一行。我怎么读所有的线?安卓

时间:2014-08-19 14:56:56

标签: java android readline

此代码仅读取第一行。我怎么能阅读所有的文字。

这是我的完整代码:

package com.example.gdrgrg;

 import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.net.HttpURLConnection;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.ArrayList;

 import android.os.Bundle;
 import android.app.Activity;
 import android.app.ProgressDialog;
 import android.util.Log;
 import android.view.Menu;
 import android.view.View;
 import android.view.View.OnClickListener;
 import android.widget.ArrayAdapter;
 import android.widget.Button;
 import android.widget.EditText;
 import android.widget.ListView;
  import android.widget.TextView;





  public class MainActivity extends Activity {
  ProgressDialog dialog = null;

  @Override
 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);




    ////////////////////////

    final Button b=(Button) findViewById(R.id.button1);


    b.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {

            dialog = ProgressDialog.show(MainActivity.this, "", "wait...", true);
    new Thread(new Runnable() {
            public void run() {


                 uploadFile();

            }
          }).start(); 

        }
    });



    ////////////////////////////




}//on create end


public int uploadFile() {

    final EditText et = (EditText) findViewById(R.id.editText1);

   // final TextView tv =(TextView)findViewById(R.id.textView1);
 HttpURLConnection connection = null;
InputStream is = null;


try{

connection = (HttpURLConnection) (new URL("http://sinhaladic.com/a/?enask=go" )).openConnection();
 connection.setRequestMethod( "GET" );
 connection.setConnectTimeout(5000);
 connection.setReadTimeout(10000);
  connection.setRequestProperty("Connection", "Keep-Alive");
  connection.setDoInput( true );
 connection.setDoOutput( true );
   connection.connect();


  //Read the response

 is = connection.getInputStream();

BufferedReader br = new BufferedReader(new InputStreamReader(is));      String line = null;

line = br.toString();     et.append(线+ “H”);

 is.close();
 connection.disconnect();




 }catch ( Exception e ){
e.printStackTrace();
}finally {
 try{ is.close(); }catch ( Throwable t ){}
 try{ connection.disconnect(); } catch ( Throwable t ){};
  }




 dialog.dismiss();

    return 1;




}





 }

1 个答案:

答案 0 :(得分:0)

et.append(line + "\n");

否则et将包含一个长行。