Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. private boolean processFile(boolean vigenere)
  2. {
  3. boolean success=true;
  4.  
  5. if(processFileName()) // verify file name processing was successful
  6. {
  7. String outFile =fileName.substring(0, fileName.length()-1) + outType + ".txt";
  8. try
  9. {
  10. FileReader fr = new FileReader(file);
  11. FileWriter fw = new FileWriter(outFile);
  12. Scanner s = new Scanner(fr);
  13.  
  14. while (s.hasNextLine())
  15. {
  16.  
  17. String[] line = s.nextLine().split(" "); // read file line by line, each line as an array of words
  18.  
  19. for (int i = 0; i < line.length; i++) // parse individual words
  20. {
  21. String word = line[i];
  22. for (int j = 0; j < word.length(); j++) // process each char in each word
  23. {
  24. char c = word.charAt(j);
  25. if (isUpper("" + c)) // only upper case alphabetical characters get converted by cipher operation
  26. {
  27. c = cipherOp(vigenere, encode, c); // perform cipher operation
  28. lfreq.addChar(c); // add character to letter frequency tallies
  29. }
  30. fw.write(c); // write character to file
  31. }
  32. fw.write(" "); // add space between each word
  33. }
  34. fw.write("\r\n"); // EOL character between each line
  35. }
  36. fw.close(); // close and save output file when all lines from input file have been processed
  37. fr.close();
  38. s.close();
  39. }
  40. catch (IOException ioe) {
  41. JOptionPane.showMessageDialog(null, "File not found. Ensure file name is correct and file is in appropriate directory.");
  42. success = false;
  43. }
  44. }
  45.  
  46. return success;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement