/**
* 读取输入流数据
* @param inStream
* @return
*/
public static byte[] read(InputStream inStream) throws Exception{
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len = 0;
while( (len = inStream.read(buffer)) != -1 ){
outStream.write(buffer, 0, len);
}
inStream.close();
return outStream.toByteArray();
}
/**
*
* @param 文件名称
* @param 文件内容
* @throws 异常信息
*/
public void save(String fileName, String fileContext) throws Exception {
// 私有操作模式:创建出来的文件只能被本应用访问,其它应用无法访问该文件,另外采用私有操作模式创建的文件,写入文件中的内容会覆盖原文件的内容
FileOutputStream outStream = context.openFileOutput(fileName,
Context.MODE_PRIVATE);
outStream.write(fileContext.getBytes());
outStream.close();
}
/**
*
* @param 文件名称
* @param 文件内容
* @throws 异常信息
*/
public void saveToSDCard(String fileName, String context) throws Exception {
// 私有操作模式:创建出来的文件只能被本应用访问,其它应用无法访问该文件,另外采用私有操作模式创建的文件,写入文件中的内容会覆盖原文件的内容
File file = new File(Environment.getExternalStorageDirectory(),
fileName);
FileOutputStream outStream = new FileOutputStream(file);
outStream.write(context.getBytes());
outStream.close();
}