java编写快捷,用Java编写数百万个小文本文件的快捷方法?

我必须转储600万个文件,其中包含大约100-200个字符,而且速度很慢.实际的慢速部分是文件写入,如果我评论该部分(对WriteSoveraFile方法的调用)整个事情在5-10分钟内运行.事实上,我在一夜之间(16小时)运行并完成了200万条记录.

>有更快的方法吗?

>我最好创建一个数组数组,然后立即将它们全部转储? (我的系统只有4 GB,不会死于此消耗的6 GB数据?)

这是程序:

public static void WriteSoveraFile(String fileName, String path, String contents) throws IOException {

BufferedWriter bw = null;

try {

String outputFolderPath = cloGetAsFile( GenCCD.o_OutER7Folder ).getAbsolutePath() ;

File folder = new File( String.format("%1$s/Sovera/%2$s/", outputFolderPath, path) );

if (! folder.exists()) {

folder.mkdirs();

/* if (this.rcmdWriter != null)

this.rcmdWriter.close();

*/

}

File file = new File( String.format("%1$s/%2$s", folder.getAbsolutePath(),fileName) );

// if file doesnt exists, then create it

if (!file.exists()) {

file.createNewFile();

FileWriter fw = new FileWriter(file.getAbsoluteFile());

bw = new BufferedWriter(fw);

bw.write(contents);

bw.close();

}

/* else {

file.delete(); // want to delete the file?? or just overwrite it??

file.createNewFile();*/

} catch (IOException e) {

e.printStackTrace();

} finally {

try {

if (bw != null) bw.close();

} catch (IOException ex) {

ex.printStackTrace();

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值