common.io.FileUtils大数据输出报错

FileUtils.writeStringToFile(file, content, DEFAULT_ENCODING);

FileUtils只提供了writeLines和writeStringtoFile方法

在输出大数据时,content.getBytes会引起内存溢出

FileOutputStream fos = new FileOutputStream(file);
bw = new BufferedWriter(new OutputStreamWriter(fos,DEFAULT_ENCODING));
int length = content.length();
int start = 0;
while(length > 10000){
	String str = new String(content.substring(start*10000, (start+1)*10000));
	bw.write(str);
	start++;
	length -= 10000;
}
if(length > 0){
	String str = new String(content.substring(start*10000));
	bw.write(str);
}
bw.close();

你可能感兴趣的:(common.io.FileUtils大数据输出报错)