2015/7/20 问题集
字节流如何转换为字符流
FileInputStream fis = new FileInputStream("c:/abc.txt");// 字节流
InputStreamReader isr = new InputStreamReader(fis);// 字符流
BufferedReader br = new BufferedReader(isr);// 缓冲流
String str = null;
if ((str = br.readLine()) != null) {
System.out.println(str);
}
br.close();
isr.close();
fis.close();
}
去除文件中的空格和回车
content_str=etSend.getText().toString();
//去除空格
String drop=content_str.replace(" ","");
// 去除回车
String droph=drop.replace("\n","");
LayoutInflater加载布局
findViewById加载控件,LayoutInflater加载布局
LayoutInflater layoutInflater=LayoutInflater.from(context);
layout= (RelativeLayout) layoutInflater.inflate(R.layout.left_item,null);
新建http连接
protected String doInBackground(String... strings) {
try {
client=new DefaultHttpClient();
httpGet=new HttpGet(url);
httpResponse= client.execute(httpGet);
entity= httpResponse.getEntity();
InputStream is=entity.getContent();
InputStreamReader isr=new InputStreamReader(is);
BufferedReader br=new BufferedReader(isr);
String line;
StringBuffer sb=new StringBuffer();
while ((line=br.readLine())!=null){
sb.append(line);
}
return sb.toString();
} catch (IOException e) {
e.printStackTrace();
}