所以我一直在研究一个程序,使用邮戳通过GUI发送电子邮件。我的问题是它有效,但我有一个订阅列表和一个未订阅列表。
我试图实现的是扫描子床和未子床,然后发送一串电子邮件,其中包含从子床中删除的未子床并将其发送到另一个变量。我通过以下方式实现了这一目标的一半:
public static void getEmail() throws Exception{
File Emailpath = new File(EmailListPath);
File Unsubpath = new File("c:\test\PostMark\unsubbedEmailList.txt");
FileInputStream fis = new FileInputStream(Emailpath);
InputStreamReader isr = new InputStreamReader(fis);
FileInputStream unsubInput = new FileInputStream(Unsubpath);
InputStreamReader unsubisr = new InputStreamReader(unsubInput);
Scanner readEmail = new Scanner(Emailpath);
Scanner readUnsub = new Scanner(Unsubpath);
int i = 0;
System.err.println("Subbed List: ");
while (readEmail.hasNext()) {
//i++;
String line = readEmail.nextLine();
System.err.println(line);
EmailAddress = EmailAddress+","+line;
}
System.err.println("nUnsubbed List: ");
while (readUnsub.hasNext()) {
//i++;
String line = readUnsub.nextLine();
System.err.println(line);
unsubbedEmailAddress = unsubbedEmailAddress+","+line;
}
//System.err.println("n"+EmailAddress);
unsubbedEmailAddress=unsubbedEmailAddress.substring(1, unsubbedEmailAddress.length());
EmailAddress=EmailAddress.substring(1, EmailAddress.length());
EmailAddress = EmailAddress.replaceAll(unsubbedEmailAddress,"");
System.err.println("Subbed:n"+EmailAddress);
System.err.println("Unsubbed:n"+unsubbedEmailAddress);
System.err.println("nSending to:n"+EmailAddress);
最后几行一半做了我想要的,但未子床必须按特定顺序才能从子床字符串中正确删除。
所以我在想这样的事情?相反,字符串将从文件中读入,但基本上做同样的工作......
String subbed = "aaronjoyce2@gmail.com,aaronjoyce09@gmail.com,aaronscallyjoyce@gmail.com",
unsubbed = "aaronjoyce09@gmail.com";
String[] subbedArray, unsubbedArray, sendArray = null;
subbedArray = subbed.split(",");
for(int i = 0;i<=subbedArray.length -1;i++){
//System.err.println("Subbed:");
System.out.println(subbedArray[i]);
}
System.err.println("n");
unsubbedArray=unsubbed.split(",");
for(int i = 0;i<=unsubbedArray.length-1;i++){
System.out.println(unsubbedArray[i]);
}
System.err.println("n");
for(int i = 0;i<=unsubbedArray.length-1;i++){
int j=0;
if(subbedArray[i].equals(unsubbedArray[j]))
sendArray[i]= unsubbedArray[i];
else
for(j = 0;j<=unsubbedArray.length-1;j++){
if(subbedArray[i].equals(unsubbedArray[j]))
sendArray[i]= unsubbedArray[i];
}
System.out.println(sendArray[i]);
}
String subbed = "aaronjoyce2@gmail.com,aaronjoyce09@gmail.com,aaronscallyjoyce@gmail.com",
unsubbed = "aaronjoyce09@gmail.com";
ArrayList<String> subbedArray=new ArrayList<String>();
ArrayList<String> unsubbedArray=new ArrayList<String>();
ArrayList<String> sendArray=new ArrayList<String>();
subbedArray = Arrays.asList(subbed.split(","));
unsubbedArray =Arrays.asList(unsubbed.split(","));
for(int i = 0;i<unsubbedArray.size();i++){
for(int j=0;j<subbedArray.size();j++){
if(unsubbedArray.get(i).equals(subbedArray.get(j))){
subbedArray.remove(j);
}
}
}
sendArray=subbedArray;
这可能有效,但我无法测试它。 把它当作一个想法并与之合作