Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private boolean processFile(boolean vigenere)
- {
- boolean success=true;
- if(processFileName()) // verify file name processing was successful
- {
- String outFile =fileName.substring(0, fileName.length()-1) + outType + ".txt";
- try
- {
- FileReader fr = new FileReader(file);
- FileWriter fw = new FileWriter(outFile);
- Scanner s = new Scanner(fr);
- while (s.hasNextLine())
- {
- String[] line = s.nextLine().split(" "); // read file line by line, each line as an array of words
- for (int i = 0; i < line.length; i++) // parse individual words
- {
- String word = line[i];
- for (int j = 0; j < word.length(); j++) // process each char in each word
- {
- char c = word.charAt(j);
- if (isUpper("" + c)) // only upper case alphabetical characters get converted by cipher operation
- {
- c = cipherOp(vigenere, encode, c); // perform cipher operation
- lfreq.addChar(c); // add character to letter frequency tallies
- }
- fw.write(c); // write character to file
- }
- fw.write(" "); // add space between each word
- }
- fw.write("\r\n"); // EOL character between each line
- }
- fw.close(); // close and save output file when all lines from input file have been processed
- fr.close();
- s.close();
- }
- catch (IOException ioe) {
- JOptionPane.showMessageDialog(null, "File not found. Ensure file name is correct and file is in appropriate directory.");
- success = false;
- }
- }
- return success;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement