首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2ME开发 >

J2ME无线联网技术中的HTTP联接[转]

2012-08-31 
J2ME无线联网技术中的HTTP连接[转]??? ??? }??? }??? public void start() {??? ??? Thread thread new

J2ME无线联网技术中的HTTP连接[转]
??? ??? }
??? }

??? public void start() {
??? ??? Thread thread = new Thread(this);
??? ??? try {
??? ??? ??? thread.start();
??? ??? } catch (Exception e) {
??? ??? }
??? }

??? private void getImage(String url) throws IOException {

??? ??? System.out.println();
??? ???
??? ??? System.out.println("this is the url : " + url);

??? ??? ContentConnection connection = (ContentConnection) Connector.open(url);

??? ??? System.out.println("connection : " + connection);

??? ??? DataInputStream iStrm = connection.openDataInputStream();
??? ???
??? ??? System.out.println("iStrm: " + iStrm);
??? ???
??? ??? ByteArrayOutputStream bStrm = null;
??? ??? Image im = null;
??? ??? try {
??? ??? ??? byte imageData[];
??? ??? ??? int length = (int) connection.getLength();
??? ??? ??? if (length != -1) {
??? ??? ??? ??? imageData = new byte[length];
??? ??? ??? ??? iStrm.readFully(imageData);
??? ??? ??? } else {
??? ??? ??? ??? bStrm = new ByteArrayOutputStream();
??? ??? ??? ??? int ch;
??? ??? ??? ??? while ((ch = iStrm.read()) != -1)
??? ??? ??? ??? ??? bStrm.write(ch);
??? ??? ??? ??? imageData = bStrm.toByteArray();
??? ??? ??? }
??? ??? ??? im = Image.createImage(imageData , 0 , imageData.length);
??? ??? } finally {
??? ??? ??? if (connection != null)
??? ??? ??? ??? connection.close();
??? ??? ??? if (iStrm != null)
??? ??? ??? ??? iStrm.close();
??? ??? ??? if (bStrm != null)
??? ??? ??? ??? bStrm.close();
??? ??? }
??? ??? if (im == null)
??? ??? ??? Midlet.showImage(false);
??? ??? else {
??? ??? ??? Midlet.im = im;
??? ??? ??? Midlet.showImage(true);
??? ??? }
??? }
}

?

?

?

http://www.java-cn.com/club/html/63/n-163-3.htmlj2me最佳联网方案终结版 用 J2ME 进行联网用 J2ME 进行联网http://www.ibm.com/developerworks/cn/java/wi-jio/

?

热点排行