文件读取
循环读取文件:
File[] dbfiles=new File("E:\\pengyw\\workspace1\\bbsics_dk_2.0\\log").listFiles();
for(File file:dbfiles){
String Str = JavaUtil.readUTF8File(file);
if(Str.indexOf("ception")!=-1){
System.out.println(file.getName());
}else
System.out.println(0);
}
读取文件方法
public static String readUTF8File(File file) {
FileInputStream fs;
String content = "";
try {
fs = new FileInputStream(file.getAbsolutePath());
byte data[] = new byte[1024];
int i = 0;
int len = fs.read(data);
while (len != -1) {
if (i == 0
&& (data[0] == -17 && data[1] == -69 && data[2] == -65))
content = content + new String(data, 3, len - 3, "utf-8");
else
content = content + new String(data, 0, len, "GBK");
len = fs.read(data);
i++;
}
fs.close();
} catch (FileNotFoundException e) {
} catch (IOException e) {
}
return content;
}