Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package src;
- import java.io.File;
- import java.io.FileWriter;
- import java.io.BufferedWriter;
- import java.io.BufferedReader;
- import java.io.FileReader;
- import java.io.IOException;
- import java.util.Scanner;
- import java.util.regex.Pattern;
- import java.util.regex.Matcher;
- public class Principal {
- public static boolean b = false;
- public static void main(String[] args) throws IOException {
- Scanner scan = new Scanner(System.in);
- String regex = "([\\w\\.])+@([a-zA-Z])+(\\.([a-zA-Z])+)+";
- File diretorio = new File("DiretorioCriado");
- File textoTxt = new File(diretorio, "Emails.txt");
- File textoTxt2 = new File(diretorio, "EmailsCopiados.txt");
- Pattern pattern = Pattern.compile(regex);
- diretorio.mkdir();
- diretorio = new File("DiretorioCriado\\Emails.txt");
- BufferedWriter bufferedWriter = null;
- BufferedReader bufferedReader = null;
- try{
- bufferedWriter = new BufferedWriter(new FileWriter(diretorio, true));
- bufferedReader = new BufferedReader(new FileReader(diretorio));
- diretorio.createNewFile();
- textoTxt.createNewFile();
- textoTxt2.createNewFile();
- textoTxt2.delete();
- textoTxt2.createNewFile();
- String emailArm = "";
- do {
- System.out.println("Digite um email ou '0' para sair: ");
- emailArm = scan.nextLine();
- if(!(emailArm.equals("0"))){
- bufferedWriter.write(emailArm + " ");
- bufferedWriter.newLine();
- bufferedWriter.flush();
- }
- }while(!(emailArm.equals("0")));
- char[] input = new char[500];
- bufferedReader.read(input);
- String texto = "";
- System.out.println("-----------------------------------------------");
- for(char caracteresLidos : input) {
- texto += String.valueOf(caracteresLidos);
- }
- Matcher matcher = pattern.matcher(texto);
- while(matcher.find()) {
- System.out.println(matcher.start() + " - " + matcher.group());
- }
- System.out.println("-----------------------------------------------");
- System.out.println("Deseja remover algum email (S|N)? ");
- char respostaRemover = ' ';
- while(respostaRemover != 's' && respostaRemover != 'n'){
- respostaRemover = scan.next().charAt(0);
- if(respostaRemover == 'n') return;
- }
- b = true;
- respostaRemover = Character.toUpperCase(respostaRemover);
- System.out.println("Numero do email(1..2..)? ");
- int respostaInt = scan.nextInt();
- String textoCopiado = " ";
- String str = " ";
- matcher = pattern.matcher(texto);
- int i = 0;
- while(matcher.find()) {
- i++;
- if(i != respostaInt){
- System.out.println(matcher.start() + " - " + matcher.group());
- textoCopiado = matcher.group() + "\n";
- try(BufferedWriter bw = new BufferedWriter(new FileWriter(textoTxt2, true));
- BufferedReader br = new BufferedReader(new FileReader(textoTxt2))){
- bw.write(textoCopiado);
- bw.newLine();
- bw.flush();
- }catch(IOException e){
- e.printStackTrace();
- }
- }
- }
- }catch(IOException e) {
- e.printStackTrace();
- throw new IOException("(!)Atencao, erro na classe File. :()");
- }
- }
- }
Add Comment
Please, Sign In to add comment