@SuppressWarnings("unchecked")
public String[] readfile(String filepath) throws Exception {
FileReader fr = new FileReader(filepath);
// 将无法识别的字节赋值为'?'
int c = 63;
String errmessage = "文件编码不是GBK,不能解析";
try {
// 从文件中读取一个字符
c = fr.read();
} catch (Exception e) {
try {
fr.skip(1);
} catch (Exception ex) {
throw new Exception(errmessage, ex);
}
c = 63;
}
StringBuffer sb = new StringBuffer();
List list = new ArrayList();
while (c != -1) {
// 遇到回车符时保存该行内容,刷新缓存
if (c == 10) {
list.add(sb.toString());
sb = new StringBuffer();
try {
// 从文件中继续读取数据
c = fr.read();
} catch (Exception e) {
try {
public String[] readfile(String filepath) throws Exception {
FileReader fr = new FileReader(filepath);
// 将无法识别的字节赋值为'?'
int c = 63;
String errmessage = "文件编码不是GBK,不能解析";
try {
// 从文件中读取一个字符
c = fr.read();
} catch (Exception e) {
try {
fr.skip(1);
} catch (Exception ex) {
throw new Exception(errmessage, ex);
}
c = 63;
}
StringBuffer sb = new StringBuffer();
List list = new ArrayList();
while (c != -1) {
// 遇到回车符时保存该行内容,刷新缓存
if (c == 10) {
list.add(sb.toString());
sb = new StringBuffer();
try {
// 从文件中继续读取数据
c = fr.read();
} catch (Exception e) {
try {