FucUtil.java
1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package com.iflytek.speech.util;
import java.io.IOException;
import java.io.InputStream;
import android.content.Context;
/**
* 功能性函数扩展类
*/
public class FucUtil {
/**
* 读取asset目录下文件。
* @return content
*/
public static String readFile(Context mContext,String file,String code)
{
int len = 0;
byte []buf = null;
String result = "";
try {
InputStream in = mContext.getAssets().open(file);
len = in.available();
buf = new byte[len];
in.read(buf, 0, len);
result = new String(buf,code);
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
/**
* 读取asset目录下音频文件。
*
* @return 二进制文件数据
*/
public static byte[] readAudioFile(Context context, String filename) {
try {
InputStream ins = context.getAssets().open(filename);
byte[] data = new byte[ins.available()];
ins.read(data);
ins.close();
return data;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
}