处理文件问题 java处理50G的文件,是用多线程,还是有别的什么办法更好的提高性能 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 1.new io, FileChannel,Buffer2.JVM 内存设置大些。3。全部读的话,不加锁。4。要求事务的话,导入到DB后处理 好像都要几个小时,不过cdn被攻击了,没日志了 ?...?..? 2012-05-28?... ?..? 125.64.98.252?... ?..? 125.64.98.253?... ?..? 22kk.too9.com?... ?..? ad.975game.com?... ?..? aszt.975game.com?... ?..? bd.too9.com?... ?..? cdn.fengzhishen.com?... ?..? cdn.fengzhishen.com:80?... ?..? cdsy.youkia.info?... ?..? edu.qianlong.com?... ?..? game.xl.56uu.com?... ?..? i4.cvimage.cn这种格式的文件,如果最后文件名是ip过滤掉不去分析怎么写?? String filename = "kjasklaf192.168.22.56"; Pattern p = Pattern.compile("\\S*\\d+\\.\\d+\\.\\d+\\.\\d+$"); Matcher m = p.matcher(filename); System.out.println(m.matches());true就是符合,false就是不符合。 Pattern p = Pattern.compile("\\S*\\d+\\.\\d+\\.\\d+\\.\\d+$");这有个结尾符号,应该是可以的哦,亲。 File f = new File("...");if ( f.isFile()){ //是文件。 ...} /opt/haproxy_temp_log/125.46.105.54 is null/opt/haproxy_temp_log/183.234.49.176/2012-05-28/zs.22lc.com/opt/haproxy_temp_log/183.234.49.176/2012-05-28/zs.001tg.com/opt/haproxy_temp_log/183.234.49.176/2012-05-28/game.xl.56uu.com/opt/haproxy_temp_log/183.234.49.176/2012-05-28/pvz-sina.youkia.info/opt/haproxy_temp_log/183.234.49.176/2012-05-28/res1.adyun.com:80/opt/haproxy_temp_log/183.234.49.176/2012-05-28/img.91yiwu.com:80/opt/haproxy_temp_log/183.234.49.176/2012-05-28/s1.shen.mop.com/opt/haproxy_temp_log/183.234.49.176/2012-05-28/static.xiaba.cvimage.cn/opt/haproxy_temp_log/183.234.49.176/2012-05-28/dpcq.17gamer.com/opt/haproxy_temp_log/183.234.49.176/2012-05-28/cdn.uushiji.cn/opt/haproxy_temp_log/183.234.49.176/2012-05-28/cdn.fengzhishen.com/opt/haproxy_temp_log/183.234.49.176/2012-05-28/pic.hyyxw.net/opt/haproxy_temp_log/183.234.49.176/2012-05-28/www.lusen.com/opt/haproxy_temp_log/183.234.49.176/2012-05-28/yktc.youkia.info/opt/haproxy_temp_log/183.234.49.176/2012-05-28/22kk.too9.com/opt/haproxy_temp_log/183.234.49.176/2012-05-28/zs.001tg.com:80/opt/haproxy_temp_log/183.234.49.176/2012-05-28/s8.pvz.360.youkia.info/opt/haproxy_temp_log/183.234.49.176/2012-05-28/ls.sntaro.com/opt/haproxy_temp_log/183.234.49.176/2012-05-28/tg1.553.com/opt/haproxy_temp_log/183.234.49.176/2012-05-28/yyimg.blbao.com:80/opt/haproxy_temp_log/183.234.49.176/2012-05-28/s1.ssol.8787.com/opt/haproxy_temp_log/183.234.49.176/2012-05-28/s2.7k7k.youkia.info/opt/haproxy_temp_log/183.234.49.176/2012-05-28/s1.kuaiwan.youkia.info/opt/haproxy_temp_log/183.234.49.176/2012-05-28/cdn.fengzhishen.com:80/opt/haproxy_temp_log/183.234.49.176/2012-05-28/www.6801.com/opt/haproxy_temp_log/183.234.49.176/2012-05-28/s2.kaixin001.youkia.info/opt/haproxy_temp_log/183.234.49.176/2012-05-28/long.975game.com/opt/haproxy_temp_log/183.234.49.176/2012-05-28/et.img.anzhi.com /opt/haproxy_temp_log/183.234.49.176/2012-05-28/183.234.49.179就是说最后一级目录匹配下是不是ip 多起几个线程(一个线程一个大目录)调用下面的方法。 private static void listFile(File path) { // 遍历出的各个文件全路径 File[] files; files = path.listFiles(); // 得到一个由文件和目录组成的数组; if (files == null) { // 如果文件夹不存在或者没有其他文件目录的话,直接返回 return ; } Arrays.sort(files); // 把数组按升序排列; for (int i = 0; i < files.length; i++) { // 进行相关操作 // 递归 if (files[i].isDirectory()) // 测试是否为目录; { listFile(files[i]); } else { analyzeFile(files[i]); } } } private void analyzeFile( File f ) { .... } 不了解你所说的处理是怎么处理,下载的话用多线程,(无论是多核还是单核的cpu)都可以提高带宽占用率。如果是在本机上对文件进行处理,如果cpu是多核的,当然是选择多线程。但如果cpu是单核的,多线程还没有单线程快。 不用线程有其它办法吗?还有一个问题,谁知道怎么在linux控制台上输出中文~ String filename = "192.168.22.56"; Pattern p = Pattern.compile("^\\d+\\.\\d+\\.\\d+\\.\\d+$"); Matcher m = p.matcher(filename); System.out.println(m.matches()); 基本数据类型与其包装类有什么区别?如果用? 怎么判断一个swing窗体是不是可见啊? 多线程有几种实现方法,都是什么?同步有几种实现方法,都是什么? 怎么把JInternalFrame加上滚动条? jprogressbar问题----------简单 static 能修饰局部变量和局部方法吗? 环境变量是干什么用的? JAVA中有没有类似C中的select、poll机制的类包来实现线程并发控制 我想,,,可以吗???? 上海很水的JAVA公司 如何设置JComboBox一开始不选中任何项 java GUI
2.JVM 内存设置大些。
3。全部读的话,不加锁。
4。要求事务的话,导入到DB后处理
?... ?..? 125.64.98.252
?... ?..? 125.64.98.253
?... ?..? 22kk.too9.com
?... ?..? ad.975game.com
?... ?..? aszt.975game.com
?... ?..? bd.too9.com
?... ?..? cdn.fengzhishen.com
?... ?..? cdn.fengzhishen.com:80
?... ?..? cdsy.youkia.info
?... ?..? edu.qianlong.com
?... ?..? game.xl.56uu.com
?... ?..? i4.cvimage.cn这种格式的文件,如果最后文件名是ip过滤掉不去分析怎么写??
String filename = "kjasklaf192.168.22.56";
Pattern p = Pattern.compile("\\S*\\d+\\.\\d+\\.\\d+\\.\\d+$");
Matcher m = p.matcher(filename);
System.out.println(m.matches());
true就是符合,false就是不符合。
Pattern p = Pattern.compile("\\S*\\d+\\.\\d+\\.\\d+\\.\\d+$");
这有个结尾符号,应该是可以的哦,亲。
if ( f.isFile()){ //是文件。
...
}
/opt/haproxy_temp_log/183.234.49.176/2012-05-28/zs.22lc.com
/opt/haproxy_temp_log/183.234.49.176/2012-05-28/zs.001tg.com
/opt/haproxy_temp_log/183.234.49.176/2012-05-28/game.xl.56uu.com
/opt/haproxy_temp_log/183.234.49.176/2012-05-28/pvz-sina.youkia.info
/opt/haproxy_temp_log/183.234.49.176/2012-05-28/res1.adyun.com:80
/opt/haproxy_temp_log/183.234.49.176/2012-05-28/img.91yiwu.com:80
/opt/haproxy_temp_log/183.234.49.176/2012-05-28/s1.shen.mop.com
/opt/haproxy_temp_log/183.234.49.176/2012-05-28/static.xiaba.cvimage.cn
/opt/haproxy_temp_log/183.234.49.176/2012-05-28/dpcq.17gamer.com
/opt/haproxy_temp_log/183.234.49.176/2012-05-28/cdn.uushiji.cn
/opt/haproxy_temp_log/183.234.49.176/2012-05-28/cdn.fengzhishen.com
/opt/haproxy_temp_log/183.234.49.176/2012-05-28/pic.hyyxw.net
/opt/haproxy_temp_log/183.234.49.176/2012-05-28/www.lusen.com
/opt/haproxy_temp_log/183.234.49.176/2012-05-28/yktc.youkia.info
/opt/haproxy_temp_log/183.234.49.176/2012-05-28/22kk.too9.com
/opt/haproxy_temp_log/183.234.49.176/2012-05-28/zs.001tg.com:80
/opt/haproxy_temp_log/183.234.49.176/2012-05-28/s8.pvz.360.youkia.info
/opt/haproxy_temp_log/183.234.49.176/2012-05-28/ls.sntaro.com
/opt/haproxy_temp_log/183.234.49.176/2012-05-28/tg1.553.com
/opt/haproxy_temp_log/183.234.49.176/2012-05-28/yyimg.blbao.com:80
/opt/haproxy_temp_log/183.234.49.176/2012-05-28/s1.ssol.8787.com
/opt/haproxy_temp_log/183.234.49.176/2012-05-28/s2.7k7k.youkia.info
/opt/haproxy_temp_log/183.234.49.176/2012-05-28/s1.kuaiwan.youkia.info
/opt/haproxy_temp_log/183.234.49.176/2012-05-28/cdn.fengzhishen.com:80
/opt/haproxy_temp_log/183.234.49.176/2012-05-28/www.6801.com
/opt/haproxy_temp_log/183.234.49.176/2012-05-28/s2.kaixin001.youkia.info
/opt/haproxy_temp_log/183.234.49.176/2012-05-28/long.975game.com
/opt/haproxy_temp_log/183.234.49.176/2012-05-28/et.img.anzhi.com
就是说最后一级目录匹配下是不是ip
private static void listFile(File path) {
// 遍历出的各个文件全路径
File[] files;
files = path.listFiles(); // 得到一个由文件和目录组成的数组;
if (files == null) { // 如果文件夹不存在或者没有其他文件目录的话,直接返回
return ;
}
Arrays.sort(files); // 把数组按升序排列;
for (int i = 0; i < files.length; i++) {
// 进行相关操作
// 递归
if (files[i].isDirectory()) // 测试是否为目录;
{
listFile(files[i]);
} else {
analyzeFile(files[i]);
} }
}
private void analyzeFile( File f ) {
....
}
如果是在本机上对文件进行处理,如果cpu是多核的,当然是选择多线程。但如果cpu是单核的,多线程还没有单线程快。
String filename = "192.168.22.56";
Pattern p = Pattern.compile("^\\d+\\.\\d+\\.\\d+\\.\\d+$");
Matcher m = p.matcher(filename);
System.out.println(m.matches());