Eclipse使用BlueStacks作为android模拟器

使用HttpClient进行网络处理的基本步骤如下:

1、通过get的方式获取到Response对象。

CloseableHttpClient httpClient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet("http://www.baidu.com/");
CloseableHttpResponse response = httpClient.execute(httpGet);

2、获取Response对象的Entity。

HttpEntity entity = response.getEntity();

注:HttpClient将Response的正文及Request的POST/PUT方法中的正文均封装成一个HttpEntity对象。可以通过entity.getContenType(),entity.getContentLength()等方法获取到正文的相关信息。但最重要的方法是通过getContent()获取到InputStream对象。

3、通过Entity获取到InputStream对象,然后对返回内容进行处理。

is = entity.getContent();
sc = new Scanner(is);
// String filename = path.substring(path.lastIndexOf(‘/‘)+1);
String filename = "2.txt";
os = new PrintWriter(filename);
while (sc.hasNext()) {
	os.write(sc.nextLine());
}

使用HtppClient下载一个网页的完整代码如下:

package com.ljh.test;

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.Scanner;

import org.apache.http.HttpEntity;
import org.apache.http.HttpStatus;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;

public class DownloadWebPage{

	public static void downloadPagebyGetMethod() throws IOException {

		// 1、通过HttpGet获取到response对象
		CloseableHttpClient httpClient = HttpClients.createDefault();
		HttpGet httpGet = new HttpGet("http://www.baidu.com/");
		CloseableHttpResponse response = httpClient.execute(httpGet);

		InputStream is = null;
		Scanner sc = null;
		Writer os = null;
		if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
			try {
				// 2、获取response的entity。
				HttpEntity entity = response.getEntity();

				// 3、获取到InputStream对象,并对内容进行处理
				is = entity.getContent();
				sc = new Scanner(is);
				// String filename = path.substring(path.lastIndexOf(‘/‘)+1);
				String filename = "2.txt";
				os = new PrintWriter(filename);
				while (sc.hasNext()) {
					os.write(sc.nextLine());
				}

			} catch (ClientProtocolException e) {
				e.printStackTrace();
			} finally {
				if (sc != null) {
					sc.close();
				}
				if (is != null) {
					is.close();
				}
				if (os != null) {
					os.close();
				}
				if (response != null) {
					response.close();
				}
			}
		}

	}

	public static void main(String[] args) {
		try {
			downloadPagebyGetMethod();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}

注意:直接将HttpGet改为HttpPost,返回的结果有误,百度返回302状态,即重定向,新浪返回拒绝访问。怀疑大多网站均不允许POST方法直接访问网站。

Eclipse使用BlueStacks作为android模拟器,布布扣,bubuko.com

时间: 2024-08-08 05:38:37

Eclipse使用BlueStacks作为android模拟器的相关文章

eclipse启动两个android模拟器

废话不多说直接上图 首先在Andriod Virtual Device Manager中新建两个虚拟设备VPHONE和VPHONE-DOUBLE 准备两个andriod程序,运行其中一个程序,系统会自动启动一个虚拟设备,当运行第二个andriod程序时会弹出Andriod Device Chooser对话框,这里我们选择一个新设备 两台虚拟设备同时运行的效果图如下,可以模拟两台虚拟手机之间的通信了,是不是很嗨 Dalvik Debug Monitor Server(DDMS)是主要的Androi

Eclipse + BlueStacks调试Android应用

前期准备: 1. 准备好已经能用模拟器调试Android程序的Eclipse. 2. 下载并安装好BlueStacks.中文网址地址为http://www.bluestacks.net.cn/Download/ 准备工作完成之后,接下来就要让eclipse和BlueStacks互相沟通沟通了.先打开BlueStacks,再开eclipse,切换到DDMS透视图,可以看到Devices视图中已经找到了BlueStacks的那台模拟设备emulator-5554 ------------------

Eclipse中查看Android模拟器SD卡目录

有时候用到Android模拟器来模拟SD卡相关操作,在Eclipse中可以直接查看SD卡目录: 首先,新建模拟器的时候要创建SD卡,存储的大小根据需要创建: 启动模拟器,在Eclipse中打开视图窗口:Window--Show View--File Explorer: 可以看到下面有mnt目录,mnt--sdcard 就是SD卡的目录, 也就是代码中 Environment.getExternalStorageDirectory()  的目录: 这样就可以很直观的看到代码对sd卡的操作,比如新建

eclipse中如何查看一个android模拟器的内部文件

eclipse中如何查看一个android模拟器的内部文件,有时要在其中添加一个文件夹或是什么的,要手动的做这件事,而不能够用代码去完成时,就要用这个方法了. 1.首先,打开一个安卓模拟器. 2.这个时候,点击eclipse中DDMS图标,打开android模拟器的控件台. 3.在这里,你就能够看到这个模拟器了,同时它的一些状态,你也是可以看到的. 4.下面就点击右侧file explore就可以看到其中的文件系统了,在这里面,你就可以看到你要的文件了.

最快Android模拟器Genymotion的安装与eclipse配置完整教程

第一部分安装Genymotion和VirtualBox虚拟机 1,Genymotion模拟器可以在官网下载,但是下载前需要注册账号,账号注册后登陆,点击Download. 2,选择第一个with VirtualBox的,这个里面集成了Genytion和VirtualBox虚拟机,安装时genytion自动配置虚拟机. 3,安装完毕后,打开Genymotion. 第二部分:配置eclipse和Genytion虚拟机关联起来. 网上的通过eclipse-help中的install new softw

Eclipse中通过Android模拟器调用OpenGL ES2.0函数操作步骤

原文地址: Eclipse中通过Android模拟器调用OpenGL ES2.0函数操作步骤 - 网络资源是无限的 - 博客频道 - CSDN.NET http://blog.csdn.net/fengbingchun/article/details/11192189   1.  先按照http://blog.csdn.net/fengbingchun/article/details/10439281中操作搭建好基本的Android开发环境: 2.  打开Eclipse,-->Window-->

解决Android模拟器与Eclipse断开或连不上

在Eclipse中使用android模拟器,时常会出现断开,甚至重启都连接不上. 今天用模拟器调试过程中与Eclipse断开,重启模拟器,重启Eclipse都连接不上: 好在找到了解决方法,在此记录一下: 1.找到Eclipse的Devices窗口,点开窗口右边的下拉箭头 view menu 点击 Reset adb 重启adb服务: (如果Eclipse中没有Devices窗口:Window -> Show Views ->Other-> Device) 如果重启成功,还没连接上的话,

Android模拟器genymotion安装与eclipse 插件安装

推荐一款Android模拟器"Genymotion",有点速度快,占用资源少,可整合eclipse.闲话少谈,看安装步骤. 1.下载地址:https://www.genymotion.com/#!/download 2.下面需要登录,我们来注册个账号.账号必须要注册!后面会用到.账号注册不表. 3.下载后安装过程不表,无甚注意项. 4.启动“Genymotion”,新建设备.这里就需要登录,选择android设备啦. 5.选择设备并安装完毕后,就可以启动了. -------------

Eclipse+Android开发:Android模拟器快捷键

Android模拟器快捷键: 按键 按键作用  Home  Home key  Home键  ESC  Back Key  后退键  F1  Menu key  菜单键  F2  Star key  星号键  F3  Call key  发送拨号键  F4  End Call key  结束通话或红键  PgUp  Menu key  菜单键  PgDown  Star key  星号键  F7  Power button  电源键  F8  Disable/Enable all network