Android常用工具方法

2021-07-10 14:08:33 字數 1358 閱讀 5376

/* 1.

* 從流中解析新聞集合

* 使用pull解析器解析xml資料

*/ private static listgetnewlistfrominputstream(inputstream is) throws exception else if ("new".equals(tagnme))else if ("title".equals(tagnme)) else if ("detail".equals(tagnme)) else if ("comment".equals(tagnme)) else if ("image".equals(tagnme))

break;

case xmlpullparser.end_tag:

if("new".equals(tagnme))

break;

default:

break;

}eventtype = parser.next();

} return newinfolist;

} 2.從輸入流中讀取資料(可轉換為字串)

// 將流轉換成字串

private static string getstringinputstream(inputstream is)

throws ioexception

/*is.close();

return bos.tobytearray(); //從流中讀出資料返回出去

*/is.close();

// string html = bos.tostring();//把流中資料轉換成字串 採用的是utf-8

string html = new string(bos.tobytearray(), "gbk");// 在客戶端更改,接收gbk編碼格式,轉換成字串

bos.close();

return html;

} (讀一串字串,一串!用字元流比較方便。。位元組流向字元流的轉換。

fileinputstream fis = new fileinputstream(path)1.先定義乙個字元流物件。

bufferedreader reader = new bufferedreader();()裡面接收的是乙個reader的物件,就是那個轉換流

bufferedreader reader = new bufferedreader(new inputstreamreader(fis));

3.//根據路徑得到image(bitmap) 載入網路

public static bitmap getimage(string path) catch (exception e)

return bitmap;

}

android常用工具類

import android.content.context import android.net.connectivitymanager import android.net.networkinfo import android.widget.toast 常用的工具類集合!public class...

Android 工具類 常用工具類(方法)大全

1.獲取手機解析度 獲取手機解析度 public static string getdisplaymetrix context context else constant.screen screen width width constant.screen screen height height r...

js 常用工具方法

1 cookie 操作 setcookie about 設定cookie 預設乙個月失效 function setcookie name,value getcookie about 獲取cookie function getcookie name else delcookie about 刪除coo...