public?String?ReadFile(){
String?content=null;
try?{
FileInputStream?fis=openFileInput("a.txt");
ByteArrayOutputStream?baos=new?ByteArrayOutputStream();
byte[]?buffer=new?byte[1024];
int?bytes;
while((bytes=fis.read(buffer,0,buffer.length))!=-1){
baos.write(buffer,0,bytes);
}
content=baos.toString();
}?catch?(FileNotFoundException?e)?{
//?TODO?Auto-generated?catch?block
e.printStackTrace();
}?catch?(IOException?e)?{
//?TODO?Auto-generated?catch?block
e.printStackTrace();
}
return?null;
}
這段代碼content=baos.toString(); 不是很理解 怎么就把寫(xiě)到字節(jié)數(shù)組里面的字節(jié)轉(zhuǎn)換成字符串賦給content了 請(qǐng)老師做一下解釋
voice_java
2015-08-28 08:28:27