package android.poem;
import java.io.BufferedInputStream;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import org.apache.http.util.ByteArrayBuffer;
import org.apache.http.util.EncodingUtils;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class poem extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tv = new TextView(this);
String myString = null;
try{
URL myURL= new URL("http://220.181.111.57/");
URLConnection ucon = myURL.openConnection();
InputStream is = ucon.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
ByteArrayBuffer baf = new ByteArrayBuffer(50);
int current = 0;
while((current = bis.read()) != -1)
{
baf.append((byte)current);
}
myString = EncodingUtils.getString(baf.toByteArray(),"UTF-8");
}
catch(Exception e)
{
myString = e.getMessage();
}
tv.setText(myString);
this.setContentView(tv);
}
}
转载于:https://my.oschina.net/jimwind/blog/16718