java处理大文件类型

public static  String getFileContent(String fileUrl){
String filePath = Config.SAVE_PATH;
byte b[] = new byte[10240];
int len = 0;
int temp = 0;
StringBuffer str = new StringBuffer();
Calendar calendar = Calendar.getInstance(TimeZone.getDefault(),Locale.CHINESE);
String fileName = "";
fileName = fileUrl.substring(fileUrl.lastIndexOf("/")+1,fileUrl.length());
File f=new File(filePath+"\\"+calendar.get(calendar.YEAR)+"\\"+(calendar.get(calendar.MONTH) + 1)+"\\"+calendar.get(calendar.DAY_OF_MONTH)+"\\"+fileName);

FileInputStream is = null;
BufferedInputStream bis=null;
try {
is = new FileInputStream(f);
bis=new BufferedInputStream(is);
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
try{
while ((temp = bis.read()) != -1) {
if(len==10239){
str.append(new String(b, 0, len));
Arrays.fill(b,(byte)0);
len = 0 ;
temp = 0 ;
}else{
b[len] = (byte) temp;
len++;
}
}

}
catch (Exception e) {
e.printStackTrace();
}finally{
str.append(new String(b, 0, len));
try {
bis.close();
is.close();
} catch (Exception e) {
e.printStackTrace();
}
}
return str.toString();
}

你可能感兴趣的:(java)