Advertisement
allerost

kryptera

Jan 18th, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.28 KB | None | 0 0
  1. public static void makeObscure() throws IOException {
  2.         File obscure = new File("C:\\Users\\Greattech\\Downloads\\obscure.txt");
  3.         FileReader fileReader = new FileReader("C:\\Users\\Greattech\\Downloads\\lovecraft.txt");
  4.         Scanner readFile = new Scanner(fileReader);
  5.         FileWriter printer = null;
  6.         String currentRow = "";
  7.         String newRow = "";
  8.         StringBuilder builder = new StringBuilder(currentRow);
  9.         int ascii = 0;
  10.         char newchar;
  11.  
  12.         if(!obscure.exists()){
  13.             obscure.createNewFile();
  14.         }else{
  15.             //File already exists
  16.         }
  17.  
  18.         try{
  19.             printer = new FileWriter(obscure);
  20.             throw new FileNotFoundException("File not found");
  21.         } catch (FileNotFoundException | UnsupportedEncodingException e) {
  22.             e.getMessage();
  23.         }
  24.  
  25.         while(readFile.hasNextLine()){
  26.             currentRow = readFile.nextLine();
  27.             for (int i = 0; i < currentRow.length(); i++) {
  28.                ascii = (int) currentRow.charAt(i);
  29.                ascii += 3;
  30.                newchar = (char) ascii;
  31.                builder.insert(i,newchar);
  32.                newRow = builder.toString();
  33.                printer.write(newRow);
  34.             }
  35.         }
  36.  
  37.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement