⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 loademails.java

📁 基于java的电子邮件群发系统,基于java的电子邮件群发系统
💻 JAVA
字号:
package com.cwq.batchmail.util;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

import com.cwq.batchmail.mail.AbstractMailThreads;

public class LoadEmails {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		//File f = new File("F:\\eclipse-SDK-3.2-win32\\workspace\\batchmail\\src\\res\\emails.txt");
		//try { clean(f); } catch(Exception ex) { ex.printStackTrace(); }
	}
	
	//public static final String mailRegex = "([a-z0-9+_]|\\-|\\.)+@(([a-z0-9_]|\\-|\\.)+\\.)+[a-z]{2,6}";
	
	private int totalEmailsCount = 0;
	
	Set<String> load(File f) throws IOException {
		Set<String> emails = new HashSet<String>();
		
		BufferedReader reader = new BufferedReader(new FileReader(f));
		String line = null;
		while ((line = reader.readLine()) != null) {
			line = line.trim();
			if(line.length() > 0 && line.matches(AbstractMailThreads.mailRegex)) {
				emails.add(line);
				totalEmailsCount ++;
			}
		}
		try { reader.close(); } catch(Exception ex) {}
		
		return emails;
	}
	
	public Set<String> load(File f, final int limit) throws IOException {
		Set<String> emails = new HashSet<String>();
		
		BufferedReader reader = new BufferedReader(new FileReader(f));
		String line = null;
		while ((line = reader.readLine()) != null) {
			line = line.trim();
			if(line.length() > 0 && line.matches(AbstractMailThreads.mailRegex)) {
				totalEmailsCount ++;
				if(totalEmailsCount <= limit)
					emails.add(line);
			}
		}
		try { reader.close(); } catch(Exception ex) {}
		
		return emails;
	}
	
	public Set<String> clean(File f) throws IOException {
		Set<String> emails = load(f);
		save(f, emails);
		return emails;
	}
	
	static void save(File f, Set<String> emails) throws IOException {
		
		BufferedWriter writer = new BufferedWriter(new FileWriter(f));
		final int BUFFER_SIZE = 1024;
		int count = 0;
		for(Iterator<String> it = emails.iterator(); it.hasNext(); ) {
			writer.write(it.next().concat("\r\n"));
			if(count ++ > BUFFER_SIZE)
				writer.flush();
		}
		writer.flush();
		try { writer.close(); } catch(Exception ex) {}
	}

	public int getTotalEmailsCount() {
		return totalEmailsCount;
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -