/**
* 以字节为单位读取文件,常用于读二进制文件,如图片、声音、影像等文件。
* @param filePath彩信文件(.smil)的路径
*/
public String readFileByBytes(String filePath){
String content="";
File file = new File(filePath);
ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
InputStream in = null;
byte[] tempbytes = new byte[100];
try {
in = new FileInputStream(file);
int tempbyte=0;
while ((tempbyte = in.read(tempbytes)) != -1) {
out.write(tempbytes, 0, tempbyte);
}
in.close();
content= out.toString();
} catch (IOException e) {
e.printStackTrace();
}
finally {
if (in != null){
try {
in.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
return content;
}
/** * BASE64Encoder 加密,如果要实现彩信发送要把从文件读出的内容加密码再发到网关 * @param str * @return * @throws Exception */private String encrypt(String seacret) throws Exception { if (seacret == null || seacret.equals("")) { return ""; } BASE64Encoder encoder = new BASE64Encoder(); return encoder.encode(seacret.getBytes()); }