I have a need to write a large number of different small files(about 30kb per file).Below is my java code:
for(every file){
File destFile = new File(fileName);
try {
FileOutputStream fos = new FileOutputStream(destFile);
BufferedOutputStream bos = new BufferedOutputStream(fos);
// System.out.println(dr.readLine());
bos.write(result.getBytes(
"UTF-8"));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Of course ,for every file,I have to new a File object.But is it necessary to new fileOutputStream and BufferdOutputStream object for every distinct file?Is there a more efficient way to write a large number of small files?