①..编写useSourceViewer 类的基本框架,该类仅包括无返回值的main ()方法,该方法从参数中获取URL,通过输入缓冲和输出缓冲将该URL 原码输出.
import java.net.*;
import java.io.*;
public class useSourceViewer
{
public static void main (String[] args)
if (args.length 0)
try
//读入URL
URL u = new URL(args[0]);
InputStream in = u.openStream( );
// 为增加性能存储输入流
in = new BufferedInputStream(in);
// 将输入流连接到阅读器
Reader r = new InputStreamReader(in);
int c;
while ((c = r.read( )) != -1)
System.out.print((char) c);
}
Object o = u.getContent( );
System.out.println("I got a " ◆ o.getClass().getName( ));
catch (MalformedURLException e)
System.err.println(args[0] ◆ " is not a parseable URL");
catch (IOException e)
System.err.println(e);
} // end if
} // end main
} // end SourceViewer}
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class HttpTest {
String urlString;
public static void main(String[] args) throws Exception {
HttpTest client = new HttpTest(网址);
client.run();
public HttpTest(String urlString) {
this.urlString = urlString;
public void run() throws Exception {
//生成一个URL对象
URL url = new URL(urlString);
//打开URL
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
//得到输入流,即获得了网页的内容
BufferedReader reader = new BufferedReader(new InputStreamReader(urlConnection
.getInputStream()));
String line;
// 读取输入流的数据,并显示
while ((line = reader.readLine()) != null){
System.out.println(line);
package test;
private String u;
private String encoding;
public HttpTest(String u, String encoding) {
this.u = u;
this.encoding = encoding;
URL url = new URL(u);// 根据链接(字符串格式),生成一个URL对象
HttpURLConnection urlConnection = (HttpURLConnection) url
.openConnection();// 打开URL
BufferedReader reader = new BufferedReader(new InputStreamReader(
urlConnection.getInputStream(), encoding));// 得到输入流,即获得了网页的内容
String line; // 读取输入流的数据,并显示
while ((line = reader.readLine()) != null) {
根据具体问题类型,进行步骤拆解/原因原理分析/内容拓展等.
具体步骤如下:/导致这种情况的原因主要是......
/**
*/
package?com.example.baidumap;
import?java.util.ArrayList;
import?java.util.Collections;
import?java.util.HashSet;
import?java.util.List;
import?android.app.Activity;
import?android.os.Bundle;
import?android.text.Editable;
import?android.util.Log;
import?android.view.LayoutInflater;
import?android.view.View;
import?android.view.ViewGroup;
import?android.widget.ExpandableListView;
import?android.widget.ListView;
import?com.baidu.mapapi.map.offline.MKOLSearchRecord;
import?com.baidu.mapapi.map.offline.MKOLUpdateElement;
import?com.baidu.mapapi.map.offline.MKOfflineMap;
import?com.baidu.mapapi.map.offline.MKOfflineMapListener;
import?com.example.baidumap.adapters.OfflineExpandableListAdapter;
import?com.example.baidumap.adapters.OfflineMapAdapter;
import?com.example.baidumap.adapters.OfflineMapManagerAdapter;
import?com.example.baidumap.interfaces.OnOfflineItemStatusChangeListener;
import?com.example.baidumap.models.OfflineMapItem;
import?com.example.baidumap.utils.CsqBackgroundTask;
import?com.example.baidumap.utils.ToastUtil;
import?com.example.system.R;
public?class?BaiduOfflineMapActivity?extends?Activity?implements?MKOfflineMapListener,?OnOfflineItemStatusChangeListener
//?------------------------?Constants?------------------------
//?-------------------------?Fields?--------------------------
private?ViewPager?viewpager;
private?PagerTabStrip?pagertab;
private?MySearchView?svDown;
private?ListView?lvDown;
private?MySearchView?svAll;
private?ExpandableListView?lvWholeCountry;
private?ListView?lvSearchResult;
private?MKOfflineMap?mOffline?=?null;
private?OfflineMapManagerAdapter?downAdapter;
private?OfflineMapAdapter?allSearchAdapter;
private?OfflineExpandableListAdapter?allCountryAdapter;
private?ListOfflineMapItem?itemsProvince;
private?ListListOfflineMapItem?itemsProvinceCity;
//?-----------------------?Constructors?----------------------
//?--------?Methods?for/from?SuperClass/Interfaces?-----------
@Override
protected?void?onCreate(Bundle?savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_offline_map);
//final?String?packname?=?this.getPackageName();
//PackageInfo?packageInfo;
//try
//{
//packageInfo?=?this.getPackageManager().getPackageInfo(packname,?PackageManager.GET_SIGNATURES);
//
//if?(code?==?-00)
//?初始化离线地图管理
mOffline?=?new?MKOfflineMap();
mOffline.init(this);
initViews();
viewpager.setCurrentItem(1);
//}
//catch?(NameNotFoundException?e)
//e.printStackTrace();
private?boolean?isResumed?=?false;
protected?void?onResume()
super.onResume();
if?(!isResumed)
isResumed?=?true;
loadData();
protected?void?onDestroy()
super.onDestroy();
mOffline.destroy();
*?
*??事件类型:?MKOfflineMap.TYPE_NEW_OFFLINE,?MKOfflineMap.TYPE_DOWNLOAD_UPDATE,?MKOfflineMap.TYPE_VER_UPDATE.
*??事件状态:?当type为TYPE_NEW_OFFLINE时,表示新安装的离线地图数目.?当type为TYPE_DOWNLOAD_UPDATE时,表示更新的城市ID.
public?void?onGetOfflineMapState(int?type,?int?state)
switch?(type)
case?MKOfflineMap.TYPE_DOWNLOAD_UPDATE:
MKOLUpdateElement?update?=?mOffline.getUpdateInfo(state);
if?(setElement(update,?true)?!=?null)
if?(itemsDown?!=?null?itemsDown.size()?1)
Collections.sort(itemsDown);
refreshDownList();
else
downAdapter.notifyDataSetChanged();
allSearchAdapter.notifyDataSetChanged();
allCountryAdapter.notifyDataSetChanged();
break;
case?MKOfflineMap.TYPE_NEW_OFFLINE:
//?有新离线地图安装
Log.d("OfflineDemo",?String.format("add?offlinemap?num:%d",?state));
case?MKOfflineMap.TYPE_VER_UPDATE:
//?版本更新提示
*??有状态改变的item
*??item是否被删除
public?void?statusChanged(OfflineMapItem?item,?boolean?removed)
if?(removed)
for?(int?i?=?itemsDown.size()?-?1;?i?=?0;?i--)
OfflineMapItem?temp?=?itemsDown.get(i);
if?(temp.getCityId()?==?item.getCityId())
itemsDown.remove(i);
//?---------------------?Methods?public?----------------------
public?void?toDownloadPage()
viewpager.setCurrentItem(0);
//?---------------------?Methods?private?---------------------
private?void?initViews()
//?TODO
viewpager?=?(ViewPager)?findViewById(R.id.viewpager);
pagertab?=?(PagerTabStrip)?findViewById(R.id.pagertab);
LayoutInflater?inf?=?LayoutInflater.from(this);
View?v1?=?inf.inflate(R.layout.view_offline_download,?null,?false);
svDown?=?(MySearchView)?v1.findViewById(R.id.svDown);
lvDown?=?(ListView)?v1.findViewById(R.id.lvDown);
views.add(v1);
titles.add("城市列表");
pagertab.setTabIndicatorColor(0xff00cccc);
pagertab.setDrawFullUnderline(false);
viewpager.setAdapter(new?MyPagerAdapter());
svDown.setSearchListener(new?MySearchView.SearchListener()
public?void?afterTextChanged(Editable?text)
public?void?search(String?text)
});
svAll.setSearchListener(new?MySearchView.SearchListener()
refreshAllSearchList();
downAdapter?=?new?OfflineMapManagerAdapter(this,?mOffline,?this);
lvDown.setAdapter(downAdapter);
allSearchAdapter?=?new?OfflineMapAdapter(this,?mOffline,?this);
lvSearchResult.setAdapter(allSearchAdapter);
allCountryAdapter?=?new?OfflineExpandableListAdapter(this,?mOffline,?this);
lvWholeCountry.setAdapter(allCountryAdapter);
lvWholeCountry.setGroupIndicator(null);
private?void?refreshDownList()
String?key?=?svDown.getInputText();
if?(key?==?null?||?key.length()?1)
downAdapter.setDatas(itemsDown);
ListOfflineMapItem?filterList?=?new?ArrayListOfflineMapItem();
if?(itemsDown?!=?null?!itemsDown.isEmpty())
for?(OfflineMapItem?i?:?itemsDown)
if?(i.getCityName().contains(key))
filterList.add(i);
downAdapter.setDatas(filterList);
*?刷新所有城市搜索结果
private?void?refreshAllSearchList()
String?key?=?svAll.getInputText();
lvSearchResult.setVisibility(View.GONE);
lvWholeCountry.setVisibility(View.VISIBLE);
allSearchAdapter.setDatas(null);
lvSearchResult.setVisibility(View.VISIBLE);
lvWholeCountry.setVisibility(View.GONE);
if?(itemsAll?!=?null?!itemsAll.isEmpty())
for?(OfflineMapItem?i?:?itemsAll)
allSearchAdapter.setDatas(filterList);
private?void?loadData()
new?CsqBackgroundTaskVoid(this)
protected?Void?onRun()
//?TODO?Auto-generated?method?stub
//?导入离线地图包
int?num?=?mOffline.importOfflineData();
if?(num?0)
ToastUtil.showToastInfo(BaiduOfflineMapActivity.this,?"成功导入"?◆?num?◆?"个离线包",?false);
ListMKOLSearchRecord?all?=?null;
all?=?mOffline.getOfflineCityList();
catch?(Exception?e)
e.printStackTrace();
if?(all?==?null?||?all.isEmpty())
ToastUtil.showToastInfo(BaiduOfflineMapActivity.this,?"未获取到离线地图城市数据,可能有其他应用正在使用百度离线地图功能!",?false);
return?null;
ListMKOLSearchRecord?hotCity?=?mOffline.getHotCityList();
HashSetInteger?hotCityIds?=?new?HashSetInteger();
if?(!hotCity.isEmpty())
for?(MKOLSearchRecord?r?:?hotCity)
hotCityIds.add(r.cityID);
itemsAll?=?new?ArrayListOfflineMapItem();
itemsDown?=?new?ArrayListOfflineMapItem();
itemsProvince?=?new?ArrayListOfflineMapItem();
itemsProvinceCity?=?new?ArrayListListOfflineMapItem();
//?全国概略图、直辖市、港澳?子城市列表
ArrayListMKOLSearchRecord?childMunicipalities?=?new?ArrayListMKOLSearchRecord();
proHot.cityName?=?"热门城市";
proHot.childCities?=?cs;
ListMKOLUpdateElement?updates?=?mOffline.getAllUpdateInfo();
if?(updates?!=?null?updates.size()?0)
protected?void?onResult(Void?result)
allCountryAdapter.setDatas(itemsProvince,?itemsProvinceCity);
}.execute();
哈哈,这个我正好有,我自己做的网上商城,数据库是MySQL,服务器是Tomcat,MyEclipse是开发工具,给你传过去你看看吧.
以上就是土嘎嘎小编为大家整理的门户网站源代码Java相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!