J2ME通过URL访问XML文件并下载XML到本地
来源:互联网 发布:超声波捕鸟器淘宝网 编辑:程序博客网 时间:2024/05/17 07:59
(叶全府)J2ME通过URL访问XML文件并下载XML到本地
2009-06-11 14:45
**
* 网络连接
* 固定URL的网络连接
* @param cmnet
* true走cmnet false走cmwap
* @return返回String类型的XML数据
*/
private String connect(boolean cmnet) {
try {
if (cmnet) {
http = (HttpConnection) Connector
.open(http://xx.cn/t.xml);
} else {
http = (HttpConnection) Connector
.open(http://10.0.0.3/t.xml);
http.setRequestProperty("X-Online-Host", "xx.cn");
}
http.setRequestProperty("Content-Type", "application/octet-stream");
http.setRequestProperty("Connection", "Keep-Alive");
http.setRequestMethod(HttpConnection.GET);
// 判断是否为连接网络收费提示页面
String content_type = http.getHeaderField("Content-Type");
// 如果是返回移动的拦截页面,则重发.
if (content_type.indexOf("wml") != -1) {
try {
http.close();
} catch (IOException e) {
}
http = null;
// 重新发起一次请求
if (cmnet) {
http = (HttpConnection) Connector
.open(http://xx.cn/t.xml);
} else {
http = (HttpConnection) Connector
.open(http://10.0.0.3/t.xml);
http.setRequestProperty("X-Online-Host",
"xx.cn");
}
http.setRequestMethod(HttpConnection.GET);
}
int code = http.getResponseCode();
if (code == 200) {// 返回200 表示连接成功
// 打开输入流,读取数据
InputStreamReader is = new InputStreamReader(http
.openInputStream(), "UTF-8");
// 建一StringBuffer,用于保存已读的数据
StringBuffer sb = new StringBuffer();
// 每次读取1K的数据
char[] c = new char[1024];
int k;
// 循环读取数据,直到读完 当返回-1时表示流已读完
while ((k = is.read(c)) != -1) {
sb.append(c, 0, k);
}
is.close();
is = null;
http.close();
http = null;
return sb.toString();
}
} catch (Exception e) {
e.printStackTrace();
// return null;
} finally {
if (http != null) {
try {
http.close();
http = null;
} catch (IOException e) {
}
http = null;
}
}
return null;
}
* 网络连接
* 固定URL的网络连接
* @param cmnet
* true走cmnet false走cmwap
* @return返回String类型的XML数据
*/
private String connect(boolean cmnet) {
try {
if (cmnet) {
http = (HttpConnection) Connector
.open(http://xx.cn/t.xml);
} else {
http = (HttpConnection) Connector
.open(http://10.0.0.3/t.xml);
http.setRequestProperty("X-Online-Host", "xx.cn");
}
http.setRequestProperty("Content-Type", "application/octet-stream");
http.setRequestProperty("Connection", "Keep-Alive");
http.setRequestMethod(HttpConnection.GET);
// 判断是否为连接网络收费提示页面
String content_type = http.getHeaderField("Content-Type");
// 如果是返回移动的拦截页面,则重发.
if (content_type.indexOf("wml") != -1) {
try {
http.close();
} catch (IOException e) {
}
http = null;
// 重新发起一次请求
if (cmnet) {
http = (HttpConnection) Connector
.open(http://xx.cn/t.xml);
} else {
http = (HttpConnection) Connector
.open(http://10.0.0.3/t.xml);
http.setRequestProperty("X-Online-Host",
"xx.cn");
}
http.setRequestMethod(HttpConnection.GET);
}
int code = http.getResponseCode();
if (code == 200) {// 返回200 表示连接成功
// 打开输入流,读取数据
InputStreamReader is = new InputStreamReader(http
.openInputStream(), "UTF-8");
// 建一StringBuffer,用于保存已读的数据
StringBuffer sb = new StringBuffer();
// 每次读取1K的数据
char[] c = new char[1024];
int k;
// 循环读取数据,直到读完 当返回-1时表示流已读完
while ((k = is.read(c)) != -1) {
sb.append(c, 0, k);
}
is.close();
is = null;
http.close();
http = null;
return sb.toString();
}
} catch (Exception e) {
e.printStackTrace();
// return null;
} finally {
if (http != null) {
try {
http.close();
http = null;
} catch (IOException e) {
}
http = null;
}
}
return null;
}
- J2ME通过URL访问XML文件并下载XML到本地
- 通过网络Url下载图片并下载到本地相册
- JAVA通过访问页面中的URL实现Http文件下载到本地
- xml文件下载到本地—XmlPullParser解析下载到本地的xml(vlc)
- QTP 通过URL地址下载文件到本地
- Java通过http访问网页及xml及文件并保存到local
- Java通过http访问网页及xml及文件并保存到local
- 利用dom4j创建xml文件并保存到本地实例
- ASP.NET 将XML文件下载到本地
- 通过图片URL下载图片到本地
- 通过ajax访问xml文件
- android xml文件到本地
- DatagramSocket DatagramPacket;通过URL访问网络资源保存在本地;XML DOM解析 SAX解析 JSON解析
- java访问URL并下载文件
- J2ME中使用KXML解释本地XML文件
- java 通过url下载文件到浏览
- 服务器通过浏览器下载文件到本地
- 从url下载xml文件并解析(在流的状态直接解析)
- 改变不了的事,就不要去改变。
- ORA-00904: : invalid identifier
- 模仿url访问
- 基于HttpClient的HttpUtils(后台访问URL)
- 理解SIGBUS与SIGSEGV
- J2ME通过URL访问XML文件并下载XML到本地
- mssql中多表联合查询中去重复
- localhost不能用,但127.0.0.1可以用
- 使用Java调用Oracle数据库的存储过程实例
- 用Powershell调用DLL文件
- 试用Mapabc
- Jpa个人小结
- C语言给函数计时
- cxGrid 使用技巧