Guest User

Untitled

a guest
Nov 21st, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.45 KB | None | 0 0
  1. package src;
  2.  
  3. import java.io.File;
  4. import java.io.FileWriter;
  5. import java.io.BufferedWriter;
  6. import java.io.BufferedReader;
  7. import java.io.FileReader;
  8. import java.io.IOException;
  9. import java.util.Scanner;
  10. import java.util.regex.Pattern;
  11. import java.util.regex.Matcher;
  12.  
  13. public class Principal {
  14.  
  15. public static boolean b = false;
  16.  
  17. public static void main(String[] args) throws IOException {
  18. Scanner scan = new Scanner(System.in);
  19. String regex = "([\\w\\.])+@([a-zA-Z])+(\\.([a-zA-Z])+)+";
  20. File diretorio = new File("DiretorioCriado");
  21. File textoTxt = new File(diretorio, "Emails.txt");
  22. File textoTxt2 = new File(diretorio, "EmailsCopiados.txt");
  23. Pattern pattern = Pattern.compile(regex);
  24. diretorio.mkdir();
  25. diretorio = new File("DiretorioCriado\\Emails.txt");
  26. BufferedWriter bufferedWriter = null;
  27. BufferedReader bufferedReader = null;
  28. try{
  29. bufferedWriter = new BufferedWriter(new FileWriter(diretorio, true));
  30. bufferedReader = new BufferedReader(new FileReader(diretorio));
  31. diretorio.createNewFile();
  32. textoTxt.createNewFile();
  33. textoTxt2.createNewFile();
  34. textoTxt2.delete();
  35. textoTxt2.createNewFile();
  36. String emailArm = "";
  37. do {
  38. System.out.println("Digite um email ou '0' para sair: ");
  39. emailArm = scan.nextLine();
  40. if(!(emailArm.equals("0"))){
  41. bufferedWriter.write(emailArm + " ");
  42. bufferedWriter.newLine();
  43. bufferedWriter.flush();
  44. }
  45. }while(!(emailArm.equals("0")));
  46. char[] input = new char[500];
  47. bufferedReader.read(input);
  48. String texto = "";
  49. System.out.println("-----------------------------------------------");
  50. for(char caracteresLidos : input) {
  51. texto += String.valueOf(caracteresLidos);
  52. }
  53. Matcher matcher = pattern.matcher(texto);
  54. while(matcher.find()) {
  55. System.out.println(matcher.start() + " - " + matcher.group());
  56. }
  57. System.out.println("-----------------------------------------------");
  58. System.out.println("Deseja remover algum email (S|N)? ");
  59. char respostaRemover = ' ';
  60. while(respostaRemover != 's' && respostaRemover != 'n'){
  61. respostaRemover = scan.next().charAt(0);
  62. if(respostaRemover == 'n') return;
  63. }
  64. b = true;
  65. respostaRemover = Character.toUpperCase(respostaRemover);
  66. System.out.println("Numero do email(1..2..)? ");
  67. int respostaInt = scan.nextInt();
  68. String textoCopiado = " ";
  69. String str = " ";
  70. matcher = pattern.matcher(texto);
  71. int i = 0;
  72. while(matcher.find()) {
  73. i++;
  74. if(i != respostaInt){
  75. System.out.println(matcher.start() + " - " + matcher.group());
  76. textoCopiado = matcher.group() + "\n";
  77. try(BufferedWriter bw = new BufferedWriter(new FileWriter(textoTxt2, true));
  78. BufferedReader br = new BufferedReader(new FileReader(textoTxt2))){
  79. bw.write(textoCopiado);
  80. bw.newLine();
  81. bw.flush();
  82. }catch(IOException e){
  83. e.printStackTrace();
  84. }
  85. }
  86. }
  87. }catch(IOException e) {
  88. e.printStackTrace();
  89. throw new IOException("(!)Atencao, erro na classe File. :()");
  90. }
  91.  
  92. }
  93.  
  94. }
Add Comment
Please, Sign In to add comment